将TextBox复制到剪贴板 [英] Copy TextBox to clipboard
问题描述
我尝试复制剪贴板中的所有文本框(当我在文本框上点击左键)。我收到一个错误:未定义的用户定义类型。代码:
I try to copy all the textbox in the clipboard (when I do a left click on the textbox). I get an error: User-defined type not defined. The code:
Sub TextBox1_Click()
Dim DataObject As DataObject
Set DataObject = New DataObject
DataObject.SetText Me.TextBox1.Text
DataObject.PutInClipboard
End Sub
任何想法?
推荐答案
首先:您不能使用任何使用的名称命名变量,如类型,内置函数,...
所以更改 Dim DataObject As DataObject
to Dim AnyThingElseYouWant As DataObject
之后,如果您还有错误, 2个选项:
After that, 2 options if you still have an error :
-
您可能需要将DataObject显式引用为从Forms库,如
Dim Clipboard as MSForms.DataObject
您缺少参考:
如果 MSForms
未在引用列表中列出,请转到添加引用,然后点击浏览...按钮自己寻找文件。
If MSForms
is not listed in the References list, go to add a reference and then hit the "Browse..." button to look for the file yourself.
MSForms
在名为 FM20.dll的文件
(至少对于版本2.0;其他版本将相应编号),这可能在您的Windows \System32文件夹中。
MSForms
is in a file called FM20.dll
(at least for version 2.0; other versions would be numbered accordingly) which is probably in your Windows\System32 folder.
如果找不到该文件,可能会被删除,您可能需要重新安装。
If you can't find the file, it may have somehow gotten erased and you may need to reinstall it.
这篇关于将TextBox复制到剪贴板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!