buffer (clipboard) in MS Word: thanks Rory!

trevexcel2

New Member
Joined
Aug 21, 2008
Messages
36
In Excel VBA, to manipulate the clipboard (buffer), one method is the following:

Include [Microsoft Forms 2.0 Object Library] from \ tools \ references.
Or simply add at least one userform in your project.

Code:
Dim myData As DataObject 
 
Set myData = New DataObject
 
With myData
.SetText ActiveCell.Formula 'contents of cell is obtained
.PutInClipboard 'and put it into the clipboard.
End With
 
'Below = to get it out of the clipboard again, and store it in findStr.
With myData
.GetFromClipboard
findStr = .GetText 
End With
But it only works for Excel, not MS Word (Office 2007)!

Because the Microsoft Forms 2.0 Object Libary is not in the list in MS Word, in \tools \ references! Adding a userform doesn’t help also.

But the following code, which I got from a guy named Rory (I think on this forum, and years ago), indeed works!
Code:
[FONT=Arial]dim myData as object[/FONT]
[FONT=Arial]Const dataObjStr As String = "New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}"[/FONT]
[FONT=Arial]Set myData = GetObject(dataObjStr)[/FONT]

Rory you're so great.


---oOo---
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Thanks - would you like to pop round and tell my boss that? ;)

FYI, adding a userform should work in Word just as it does in Excel.
 
Upvote 0
hahaha, you can send me his details and I'll do an impersonation.

I don't know why the userform didn't work, maybe it has to do with where I put the code? The declaration is in e.g. normal\modules\myModule1 (which contains my "auto_exec" startup macro) and I use it in normal\modules\myModule2.

My normal.dot now indeed has a normal\forms\userForm1. I tried putting the declaration there but still no luck.

It's fine now, it's just curious as you say.
 
Upvote 0
The MS Forms library is available with Office 2007.

Provided you set a reference to it and change:
'.SetText ActiveCell.Formula'
to something like:
'.SetText Selection.Text'
(since 'ActiveCell.Formula' means nothing to Word), the code will work just fine.
 
Upvote 0
I would expect so, but:

1) When in excel VBA editor, tools\ references indeed has 'Microsoft Forms 2.0 Object Library' available.

2) When in msWord VBA editor, it's nowhere to be seen in tools\ references. If you can see it in your own MSWord then something's obviously wrong on my side.
 
Upvote 0
Re: buffer (clipboard) in MS Word

Oooops, it worked now after I simply browsed in [tools \ references \ ] to the same path as the one Excel uses for [MS Forms 2.0 Object Library] i.e. C:\WINDOWS\system32\ fm20.dll.

Well that was embarrassing. I think I'll go have a coffee now...
 
Upvote 0

Forum statistics

Threads
1,225,523
Messages
6,185,467
Members
453,296
Latest member
zashue22

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