getFromClipboard函数是否可以在mac上使用?

寻找是或否。

如果答案是否定的,那么在Mac上寻找一些想法来做同样的事情。

要注意 – 我看到在谷歌最后的post处理Office 2004,我在2016年,因为我希望能build立这个代码的mac用户:)

这是有问题的代码。

Set objClipboard = New MSForms.DataObject objClipboard.GetFromClipboard On Error Resume Next 'Turns Error checking off vClipArray = Split(objClipboard.GetText(1), vbCrLf) If Err.Number <> 0 Then 'Script will error if there is no copy, etc.. MsgBox "Bad Copy, Sorry" End End If On Error GoTo HandleErrors 'Turns Error Checking on 

是。 但是这个函数有一个奇怪的问题,在这里讨论。 简单地说,它设置剪贴板文本,但通常还会添加一些随机的尾随字符。 例如,“hey”的剪贴板值会给你“heyT <”。 其中一位用户向MS报告了这个问题。

这很有趣。 我玩了一些代码的变化。 有可能得到CONSISTENT随机字符。 但是一致的随机字符中对我们更有用…我添加了一个循环,请参阅下面的代码。 它重复错误的命令1000次,并保存最短的string版本。

为了进行debugging,如果按原样运行,第一个MsgBox会给出初始结果(可能会也可能不会成功 – 注意它通常有垃圾字符),第二个MsgBox会显示最短的文本,应该是正确的。

也许我们可以运行一些分析来确定一个比1000更合理的数字。

另一种方法是比较string并找出字符在哪一点开始有所不同。

 Sub GetClipBoardText2() Dim clipboard As MSForms.DataObject Dim str1 As String On Error Resume Next Set clipboard = New MSForms.DataObject clipboard.GetFromClipboard str1 = clipboard.GetText MsgBox str1, vbOKOnly, "FIRST RESULT" 'Determine shortest result of 1000 attempts: strLenMin = 0 For i = 0 To 1000 str1 = clipboard.GetText strLen = Len(str1) If strLenMin = 0 Then 'nothing stored yet strBest = str1 strLenMin = strLen Else 'compare length to that of the shortest stored string If strLen < strLenMin Then 'it's smaller, store it strBest = str1 strLenMin = strLen End If End If Next i MsgBox strBest, vkOKOnly, "SHORTEST RESULT" If Err.Number <> 0 Then MsgBox "Bad Copy, Sorry" End If On Error GoTo 0 End Sub