Text To Clipboard in VBA Windows 10 Issue

前端 未结 7 2037
抹茶落季
抹茶落季 2020-12-03 09:04

I have a function that I use to send a string to the windows clipboard:

Sub TextToClipboard(ByVal Text As String)

  With CreateObject(\"new:{1C3B4210-F441-1         


        
相关标签:
7条回答
  • 2020-12-03 10:08

    Win10 broke MSForms.DataObject; that's why the approach that works on Win7/32 or Win7/64 don't work now. Thank you, Khang Huynh, for a simple and elegant mod to the original macro.

    I suggest a couple of tweaks:

    Option Explicit
    
    Private Sub CopyCellContents()
    
    ' dimension our vars
    
    Dim objData As New DataObject
    
    ' set the contents of the active cell as our data object, removing extraneous spaces and linebreaks 
    
    with objData
    
    .SetText Trim(ActiveCell.Text)
    
    ' write it to the Clipboard
    
    .PutInClipboard
    
    ' just for fun
    
    Application.StatusBar = .GetText
    
    End With
    
    ' clean up memory by not leaving object handles open
    
    Set objData = Nothing
    
    End Sub
    
    0 讨论(0)
提交回复
热议问题