grab clipboard contents in a macro (for find/replace)

subodhjoshi

Board Regular
Joined
Oct 22, 2002
Messages
51
I have to clean up snippets of text in a column. Snippets are different and I have to read contents to decide what needs to be removed.

I am trying to write a macro so that I can copy the text to be removed and run this macro ( fm a toolbar button ). It would save me lot of keystrokes/mouse clicks.

Just cannot figure out how to grab clipboard contents. Some snippet that would let me assign it to a text variable would be great. I think I can then use that text in the "What:= ____" part of replace statement.

Thanks a bunch for your help.

- Subodh
 
Thanks for your time again.
Unfortunately, this time, it stumbles at the FetFromClipboard stmt. I get "Object required (Error 424)". Excel help talks about confirming object qualifiers are in standard modules. Is this imilar to earlier case where I had to add MS Form 2.0 object library??

Does this run for you?
 
Upvote 0

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
I missed the fact that you had a different name for your object variable, so:

Dim MyDataObj As New DataObject

should be

Dim MyObj As New DataObject

This code worked for me (if something was on the clipboard:

Code:
Sub Test1()
    Dim MyDataObj As New DataObject
    Dim MyVar As Variant
    MyDataObj.GetFromClipboard
    MyVar = MyDataObj.GetText
    MsgBox MyVar
End Sub

If you use Option Explicit at the top of your modules you will get a compile error instead of a runtime error if you use a variable that you haven't declared. Tools, Options, Editor, Require variable declaration will do it for you automatically.
 
Upvote 0
THANKS A BUNCH buddy, you have saved me lots of keystrokes and eyestrain !

I was adding to complication by having another session of Excel which didnt have MS Forms object lib added !!

Thanks again.

- Subodh.
 
Upvote 0

Forum statistics

Threads
1,215,754
Messages
6,126,680
Members
449,328
Latest member
easperhe29

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top