microsoft word 中是否有一个函数(宏)可以自动删除剪贴板中的任何内容?
is there a function (macro) in microsoft word to auto past whatever in the clipboard?
Microsoft Word 中是否有一个函数(宏)可以自动删除剪贴板中的内容?
我正在处理宏以检查剪贴板中是否有新内容并在没有我参与的情况下将其粘贴到单词中
请试试这个方法:
在您的文档项目或 Normal.dot 中插入一个表单。必须这样做才能获得参考 ('Microsoft Forms 2.0 Object Library')。现在你可以删除它了。参考将保留。理论上可以直接加引用,但有时Word不显示可加引用;
插入一个标准模块并粘贴下一段代码:
Sub testPutfromclipboard()
Dim clp As DataObject, nextLine As String
'nextLine = vbCrLf
Set clp = New DataObject
clp.GetFromClipboard
If clp.GetFormat(1) Then
If clp.GetText <> Empty Then
ActiveDocument.Content.InsertAfter Text:=nextLine & clp.GetText
clp.SetText Text:=Empty: clp.PutInClipboard
End If
End If
End Sub
- 运行 它将和剪贴板粘贴到活动文档文本的末尾。
如果您希望将其粘贴到下一行,只需 un-comment 行 'nextLine = vbCrLf
...
你可以每秒轮询一次。
Public Declare Function GetClipboardOwner Lib "user32" () As Long
Public Declare Function GetClipboardSequenceNumber Lib "user32" () As Long
RTFString = RTFString & "\b1 Clipboard Sequence Number: \b0 " & CStr(GetClipboardSequenceNumber()) & "\par" & vbCr
RTFString = RTFString & "\b1 Clipboard Owner Window Handle: \b0 " & CStr(GetClipboardOwner()) & "\par" & vbCr
Msgbox RTFString
还有一个更好的方法,但它需要您 class 子表格。参见 https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-addclipboardformatlistener
您不需要子 class 表单,您可以子 class Excel 的主 window.
Microsoft Word 中是否有一个函数(宏)可以自动删除剪贴板中的内容? 我正在处理宏以检查剪贴板中是否有新内容并在没有我参与的情况下将其粘贴到单词中
请试试这个方法:
在您的文档项目或 Normal.dot 中插入一个表单。必须这样做才能获得参考 ('Microsoft Forms 2.0 Object Library')。现在你可以删除它了。参考将保留。理论上可以直接加引用,但有时Word不显示可加引用;
插入一个标准模块并粘贴下一段代码:
Sub testPutfromclipboard()
Dim clp As DataObject, nextLine As String
'nextLine = vbCrLf
Set clp = New DataObject
clp.GetFromClipboard
If clp.GetFormat(1) Then
If clp.GetText <> Empty Then
ActiveDocument.Content.InsertAfter Text:=nextLine & clp.GetText
clp.SetText Text:=Empty: clp.PutInClipboard
End If
End If
End Sub
- 运行 它将和剪贴板粘贴到活动文档文本的末尾。
如果您希望将其粘贴到下一行,只需 un-comment 行 'nextLine = vbCrLf
...
你可以每秒轮询一次。
Public Declare Function GetClipboardOwner Lib "user32" () As Long
Public Declare Function GetClipboardSequenceNumber Lib "user32" () As Long
RTFString = RTFString & "\b1 Clipboard Sequence Number: \b0 " & CStr(GetClipboardSequenceNumber()) & "\par" & vbCr
RTFString = RTFString & "\b1 Clipboard Owner Window Handle: \b0 " & CStr(GetClipboardOwner()) & "\par" & vbCr
Msgbox RTFString
还有一个更好的方法,但它需要您 class 子表格。参见 https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-addclipboardformatlistener
您不需要子 class 表单,您可以子 class Excel 的主 window.