且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

粘贴前检查剪贴板的内容

更新时间:2022-03-18 14:54:16

来自Excel 2003我必须说可以通过使用剪贴板来检查剪贴板内容 MSForms.DataObject 。首先必须创建对Microsoft Forms 2.0 Object库的引用(VBA窗口工具/引用)(通常在... \system32\FM20.DLL中找到)。

Coming from Excel 2003 I must say it is possible to examine the clipboard content by making use of the MSForms.DataObject. You first have to create a reference (VBA window tools / reference) to the Microsoft Forms 2.0 Object library (usually found at ...\system32\FM20.DLL).

然后,您可以将剪贴板读入文本变量:

Then you can read the clipboard into a text variable:

Dim BufObj As MSForms.DataObject, BufTxt as String

Set BufObj = New MSForms.DataObject
BufObj.GetFromClipboard
BufTxt = Buf.GetText

缓冲区文本将保持不变(至少在Win XP / SP3,MS Office 2003 SP 3中可用),并可供进一步使用,即 GetFromClipboard 不会破坏剪贴板缓冲区。这里要考虑的是剪贴板内容可以作为文本使用,因此任何图形都将以原始文本模式存储。另外,还需要考虑缓冲区大小,因为Excel中的可变长度字符串最多可以容纳ca。 2 ^ 31个字符(恕我直言,这应该足以满足所有需求的90%)。

The buffer text will remain untouched (at least in Win XP/SP3, MS Office 2003 SP 3) and available for further use, i.e. the GetFromClipboard won't destroy the clipboard buffer. The thing to consider here is that the clipboard content is available "as text" so any graphic will be stored in a raw text mode. Also the buffer size needs to be considered, as a variable length string in Excel can hold not more than ca. 2^31 characters (but IMHO this should be enough for 90% of all needs).