Excel到使用宏小数分隔符的剪贴板 [英] Excel to clipboard with macro decimal separator

查看:174
本文介绍了Excel到使用宏小数分隔符的剪贴板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将excel文件的内容复制到剪贴板,使用相同的分隔符和格式,无论用户配置如何。

I would like to copy the contents of an excel file to the clipboard, using the same separators and format regardless of user configuration.

这是我的宏: p>

Here's my macro:

Private Sub CommandButton1_Click()

'save number separators
Dim d, t, u
d = Application.DecimalSeparator
t = Application.ThousandsSeparator
u = Application.UseSystemSeparators

'set number separators
With Application
        .DecimalSeparator = "."
        .ThousandsSeparator = ","
        .UseSystemSeparators = True
End With

'create temporary copy
ActiveSheet.Copy

'set number format
ActiveSheet.Range("H2:I150").NumberFormat = "0.0000000000"

[...]

'copy sheet to clipboard
ActiveSheet.Range("A1:O150").Copy

'disable messages (clipboard)
Application.DisplayAlerts = False

'close temporary copy
ActiveWorkbook.Close SaveChanges:=False

'reenable messages
Application.DisplayAlerts = True

'reset original separators
With Application
        .DecimalSeparator = d
        .ThousandsSeparator = t
        .UseSystemSeparators = u
End With

End Sub

如果我最后没有重置原始分隔符,一切都可以正常运行,但这对我来说是不能接受的。

If I don't reset the original separators at the end, everything works fine, but this is not acceptable for me.

如果我重置分隔符(如本代码所示),那么n剪贴板的内容将具有用户特定的分隔符,而不是我在开头定义的分隔符。

If I do reset the separators (as seen in this code), then the contents of the clipboard are going to have the user specific separators, not the ones I defined at the beginning.

有关如何解决这个问题的任何想法?

Any ideas on how to fix this?

推荐答案

问题是

.UseSystemSeparators = True

将此设置为false可以解决问题。

setting this to false solves the problem.

这篇关于Excel到使用宏小数分隔符的剪贴板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆