本文介绍了将特定字符串复制到剪贴板的 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.

推荐答案

EDIT - MSForms 已弃用,因此您不应再使用我的答案.而是使用此答案:https://stackoverflow.com/a/60896244/692098

EDIT - MSForms is deprecated, so you should no longer use my answer. Instead use this answer: https://stackoverflow.com/a/60896244/692098

我在这里留下我的原始答案仅供参考:

I leave my original answer here only for reference:

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 代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 23:43