使用 Active X 控制按钮从剪贴板将超链接粘贴到活动单元格?

Paste a hyperlink to the active cell, from the clipboard, using an Active X control button?

我在从剪贴板粘贴超链接时遇到问题。目标是使用 Active X 按钮将位于剪贴板上的 hand/mouse 复制的超链接粘贴到我的作品 sheet 的“活动单元格”中。 worksheet 被保护,所以按钮必须取消保护 sheet,运行 从剪贴板粘贴超链接的代码,然后保护 sheet。对此问题的任何帮助将不胜感激。

基本思路:(我知道这段代码不正确,只是将其用作对话启动器)。

Private Sub CommandButton10_Click()
ActiveSheet.Unprotect Password:="Password1"
  Dim DataObj As MSForms.DataObject
    Set DataObj = New MSForms.DataObject
    DataObj.GetFromClipboard

    strPaste = DataObj.GetText(1)            <<<<certain something is missing after this line

    ActiveCell.Paste Link:=True
ActiveSheet.Protect Password:="Password1"
End Sub

MSForms 已弃用。使用 this function 代替:

Function Clipboard$(Optional s$)
    Dim v: v = s  'Cast to variant for 64-bit VBA support
    With CreateObject("htmlfile")
    With .parentWindow.clipboardData
        Select Case True
            Case Len(s): .setData "text", v
            Case Else:   Clipboard = .GetData("text")
        End Select
    End With
    End With
End Function

你这样称呼它:

Private Sub CommandButton10_Click()
    ActiveCell.Hyperlinks.Add ActiveCell, Clipboard
End Sub

在代码模块中,请准确添加以下所有行...

Private Sub CommandButton10_Click()
    Dim s$
    s = Clipboard
    If Len(s) Then
        ActiveSheet.Unprotect Password:="Password1"
        ActiveCell.Hyperlinks.Add ActiveCell, s
        ActiveSheet.Protect Password:="Password1"
    End If
End Sub

Function Clipboard$(Optional s$)
    Dim v: v = s  'Cast to variant for 64-bit VBA support
    With CreateObject("htmlfile")
    With .parentWindow.clipboardData
        Select Case True
            Case Len(s): .setData "text", v
            Case Else:   Clipboard = .GetData("text")
        End Select
    End With
    End With
End Function
Private Sub CommandButton43_Click()
ActiveSheet.Unprotect Password:="Password1"
ActiveCell = Clipboard
Function Clipboard$(Optional s$)
    Dim v: v = s  'Cast to variant for 64-bit VBA support
    With CreateObject("htmlfile")
    With .parentWindow.clipboardData
        Select Case True
            Case Len(s): .setData "text", v
            Case Else:   Clipboard = .GetData("text")
        End Select
    End With
    End With
End Function
 ActiveSheet.Protect Password:="Password1"
End Sub