Excel VBA代码将特定字符串复制到剪贴板 [英] Excel VBA code to copy a specific string to clipboard
本文介绍了Excel VBA代码将特定字符串复制到剪贴板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在电子表格中添加一个按钮,点击后会将特定的URL复制到我的剪贴板。
I'm trying to add a button to a spreadsheet that when clicked will copy a specific URL to my clipboard.
我有一些Excel VBA知识但是这是一段时间,我正在努力。
I had a bit of knowledge of Excel VBA but it's been a while and I'm struggling.
推荐答案
这个宏使用后期绑定将文本复制到剪贴板而不需要你设置参考。你应该能够粘贴并去:
This macro uses late binding to copy text to the clipboard without requiring you to set references. You should be able to just paste and go:
Sub CopyText(Text As String)
'VBA Macro using late binding to copy text to clipboard.
'By Justin Kay, 8/15/2014
Dim MSForms_DataObject As Object
Set MSForms_DataObject = CreateObject("new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
MSForms_DataObject.SetText Text
MSForms_DataObject.PutInClipboard
Set MSForms_DataObject = Nothing
End Sub
用法:
Sub CopySelection()
CopyText Selection.Text
End Sub
这篇关于Excel VBA代码将特定字符串复制到剪贴板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文