复制VBA剪贴板 [英] VBA Clipboard, Copy

查看:130
本文介绍了复制VBA剪贴板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看过Leigh Weber的代码:
http://social.msdn.microsoft.com/Forums/office/en-US/ee9e0d28-0f1e -467f-8d1d-1a86b2db2878 / a-clipboard-object-for-vba-including-microsoft-word?forum = worddev

I've looked at the code by Leigh Weber: http://social.msdn.microsoft.com/Forums/office/en-US/ee9e0d28-0f1e-467f-8d1d-1a86b2db2878/a-clipboard-object-for-vba-including-microsoft-word?forum=worddev

它似乎可能是解决方案的一部分我遇到的一个问题。 我正在尝试创建一个函数来确定Word文档中的选择是否不连续。 这个过程我的工作,但它涉及覆盖用户可能已经在剪贴板中有
的内容。

It seems it may be part of a solution to a issue I'm having.  I am trying to create a function to determine if the selection in a Word document is discontinuous.  The process I have works, but it involves overwriting what the user may already have in the clipboard.

如果我能以某种方式使用Leigh的类替换我的:

If I could use Leigh's class somehow to replace my:

Selection.Copy

Selection.Copy

带有东西将选择复制到此VBAClipboard,然后用户的剪贴板可能不受影响。 我无法弄清楚如何。 谢谢。

with something copies the selection to this VBAClipboard then maybe the user's clipboard would remain unaffected.  I can't figure it how.  Thanks.

Sub test()
  MsgBox IsDiscontiguous
End Sub
Function IsDiscontiguous() As Boolean
Dim lngRefCount As Long
Dim strRefText As String
Dim lngCharacterCount As Long
Dim oCB As MSForms.DataObject
Dim strCBText As String
Dim i As Long
  IsDiscontiguous = False
  If Selection.Type = wdSelectionIP Then Exit Function
  strRefText = Selection.Text
  strRefText = Replace(strRefText, Chr(10), "")
  strRefText = Replace(strRefText, Chr(11), "")
  strRefText = Replace(strRefText, Chr(13), "")
  lngRefCount = Len(strRefText)
  Selection.Copy
  Set oCB = New MSForms.DataObject
  oCB.GetFromClipboard
  strCBText = oCB.GetText
  strCBText = Replace(strCBText, Chr(10), "")
  strCBText = Replace(strCBText, Chr(11), "")
  strCBText = Replace(strCBText, Chr(13), "")
  lngCharacterCount = Len(strCBText)
  If lngRefCount <> lngCharacterCount Then
    IsDiscontiguous = True
  End If
End Function

Greg Maxey Please访问我的网站:http://gregmaxey.mvps.org/word_tips.htm

Greg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm

推荐答案

是的,宏将覆盖用户可能已经在剪贴板中的数据。

Yes, the macro will overwrite the data that the user may already have in the clipboard.

我建议您将剪贴板中的数据存储为字符串并设置剪贴板的数据结束。

I would suggest you storing data from clipboard as String and setting data of clipboard in the end.

请尝试:

Function IsDiscontiguous() As Boolean
    Dim lngRefCount As Long
    Dim strRefText As String
    Dim lngCharacterCount As Long
    Dim oCB As MSForms.DataObject
    Dim strCBText As String
    Dim temp As String
    Dim i As Long
    IsDiscontiguous = False
    If Selection.Type = wdSelectionIP Then Exit Function
    strRefText = Selection.Text
    strRefText = Replace(strRefText, Chr(10), "")
    strRefText = Replace(strRefText, Chr(11), "")
    strRefText = Replace(strRefText, Chr(13), "")
    lngRefCount = Len(strRefText)
    Set oCB = New MSForms.DataObject
    oCB.GetFromClipboard
    temp = oCB.GetText
    Selection.Copy
    Set oCB = New MSForms.DataObject
    oCB.GetFromClipboard
    strCBText = oCB.GetText
    strCBText = Replace(strCBText, Chr(10), "")
    strCBText = Replace(strCBText, Chr(11), "")
    strCBText = Replace(strCBText, Chr(13), "")
    lngCharacterCount = Len(strCBText)
    If lngRefCount <> lngCharacterCount Then
      IsDiscontiguous = True
    End If
    Set oCB = New MSForms.DataObject
    oCB.SetText (temp)
    oCB.PutInClipboard
End Function


希望这会有所帮助。

Hope this helps.


这篇关于复制VBA剪贴板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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