1

I have the following simple, Excel Macro:

Sub Macro2()
'
' Macro2 Macro
'
x = Selection.Address(False, False)
y = ActiveSheet.Name
Z = "''" & y & "'!" & x

End Sub

Is it possible to send the string named Z to the windows clipboard?

timbram
  • 1,797
  • 5
  • 28
  • 49
  • 1
    There's a few answers here that will help. I'm kind of partial to the second one with the self-contained function and the late binding to the MSForms library: http://stackoverflow.com/questions/14219455/excel-vba-code-to-copy-a-specific-string-to-clipboard – JNevill Oct 21 '14 at 17:36
  • Thank you so much! That worked amazingly! I tried searching before but didnt come accross that solution. Also, just so anyway searching for this knows, you do have to add a reference to the Microsoft Forms 2.0 Library in Tools - References in the VBE. – timbram Oct 21 '14 at 17:55

1 Answers1

0

Code that works after using:

Excel VBA code to copy a specific string to clipboard

Sub Macro2()
'
' Macro2 Macro
'
x = Selection.Address(False, False)
y = ActiveSheet.Name
Z = "''" & y & "'!" & x

With New MSForms.DataObject
    .SetText Z
    .PutInClipboard
End With

End Sub
Community
  • 1
  • 1
timbram
  • 1,797
  • 5
  • 28
  • 49