?
Solved

Excel - copy string to clipboard

Posted on 2014-03-30
7
Medium Priority
?
2,358 Views
Last Modified: 2014-03-30
Say, I don't want to copy from a cel - but rather the text in a string - its a password that needs to be put in the clipboard. I'm using a macro/VBA code.
0
Comment
Question by:shaunwingin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 27

Assisted Solution

by:MacroShadow
MacroShadow earned 1002 total points
ID: 39964832
1. Add a reference to the 'Microsoft Forms 2.0 Object Library'
2. This will put text in the clipboard:
Sub CopyToClipboard(strInput As String) 
    Dim oDataObject As New DataObject 
    oDataObject.SetText strInput 
    oDataObject.PutInClipboard 
End Sub 

Open in new window

Now
CopyToClipboard("Password")

Open in new window

Will put Password in the Windows clipboard
3. This will paste from Windows clipboard:
Sub PasteFromClipboard() 
    Dim oDataObject As New DataObject 
    oDataObject.GetFromClipboard 
    Selection = oDataObject.GetText 
End Sub 

Open in new window

0
 
LVL 24

Expert Comment

by:mankowitz
ID: 39964836
Try the following

Dim clipboard As MSForms.DataObject
Set clipboard = New MSForms.DataObject
clipboard.SetText "PASSWORD"
clipboard.PutInClipboard
0
 

Author Comment

by:shaunwingin
ID: 39964870
I don't see the reference listed for:
'Microsoft Forms 2.0 Object Library"
Using Excel 2013
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:shaunwingin
ID: 39964881
say I found it by searching for file mf20.dll
However the code doesn't work...
mankowitz
0
 
LVL 24

Assisted Solution

by:mankowitz
mankowitz earned 498 total points
ID: 39964931
The following worked for me

Private Sub button1_click()
With New MSForms.DataObject
    .SetText "password"
    .PutInClipboard
End With
End Sub

you have to make sure that msforms object is loaded. You can either add the reference as you did, or just add a userforms object to the page. You can always delete it. For example, from the Developer tab, click
Insert > more > select something like WINDOWS FORMS 2.0 TEXTBOX
0
 
LVL 27

Accepted Solution

by:
MacroShadow earned 1002 total points
ID: 39964989
Not sure why it's not working for you, works fine for me.

Perhaps Chip Pearson's article will help http://www.cpearson.com/excel/Clipboard.aspx
0
 

Author Comment

by:shaunwingin
ID: 39965015
seems I needed to change to clipboard1 as clipboard was reserved??
I also dimmed the text as a string but doubt this is needed.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question