Clear Clipboard

S

Susan

I copied this macro to (clear the clipboard) from the MVP FAQ site. But it
doesn't work.
(This is the first listing after a search for "clipboard")

Dim MyData As DataObject

Set MyData = New DataObject
MyData.SetText ""
MyData.PutInClipboard

I get an error that says:

Compile Error:
User-defined type not defined

And the "Dim MyData As DataObject" is highlighted
I'm new so I don't know what this means.
Please help
 
J

Jean-Guy Marcil

Bonjour,

Dans son message, < Susan > écrivait :
In this message, < Susan > wrote:

|| I copied this macro to (clear the clipboard) from the MVP FAQ site. But
it
|| doesn't work.
|| (This is the first listing after a search for "clipboard")
||
|| Dim MyData As DataObject
||
|| Set MyData = New DataObject
|| MyData.SetText ""
|| MyData.PutInClipboard
||
|| I get an error that says:
||
|| Compile Error:
|| User-defined type not defined
||
|| And the "Dim MyData As DataObject" is highlighted
|| I'm new so I don't know what this means.
|| Please help

In the vba - editor:
Tools > References...
check the "Microsoft forms 2.0 object library"

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
S

Susan

Windows ME
Word 2000


Thank you for your reply Jean-Guy.
But I can't find the "Microsoft forms 2.0 object library" in the window
list.

The items listed don't show any Microsoft Forms........
The list goes like this:
Microsoft Excel 9.0 Object Library
Microsoft FrontPage 4.0 Web Object Reference Library.

What should I do now?
 
J

Jonathan West

Insert a UserForm into your project and then save the template. The correct
reference will now be set. You can then delete the userform and the
reference will still be there
 
S

Susan

Thank you.
I inserted a UserForm and now the subroutine runs without
errors...............
But the clipboard doesn't get cleared!
Nothing happens when I run the sub.

I tried copy/ pasting the other examples in the MVP FAQ site and they don't
seem to work, either. (But they run without errors.)

I apologize in advance if I'm overlooking some simple mistake.
 
S

Susan

Okay, I've played with it a little bit and here's what happens.

If I run the sub then click on the little paste clipboard icon in the
toolbar, nothing gets pasted, but the clipboard window shows an item in the
box. So now, if I click the "Paste all items" icon on the clipboard itself,
then the paste happens. And after that, the little paste clipboard icon on
the toolbar starts working again, too.
 
S

Susan

Okay, I've played with it a little bit and here's what happens.

If I run the sub then click on the little paste clipboard icon in the
toolbar, nothing gets pasted, but the clipboard window shows an item in the
box. So now, if I click the "Paste all items" icon on the clipboard itself,
then the paste happens. And after that, the little paste clipboard icon on
the toolbar starts working again, too.
 
J

Jonathan West

Susan said:
Thank you.
I inserted a UserForm and now the subroutine runs without
errors...............
But the clipboard doesn't get cleared!
Nothing happens when I run the sub.

I tried copy/ pasting the other examples in the MVP FAQ site and they don't
seem to work, either. (But they run without errors.)

I apologize in advance if I'm overlooking some simple mistake.

I think we might be talking about different things. The code deals with the
simple clipboard that is common to all applications. I suspect that you are
talking of the Office multiple clipboard toolbar.

Unfortunately, the multiple clipboard isn't that well managed in terms of
programmability. However this like of code ought to clear all the entries in
the toolbar, provided you haven't customised the toolbar in any way.

Commandbars("Clipboard").Controls(4).Execute
 
S

Susan

Yes, we were talking about different things. I did not know there was a more
"basic" clipboard than the one I see in my Word application every day.

I pasted your single line of code between between Sub and End Sub and ran
it.
I have not modified the clipboard toolbar in any way (I had no idea it could
be modified in the first place)

I got this error:

Method 'Execute' of object '_Commandbarbutton' failed

I hope it's a simple thing to fix. But if not, that's okay. I've just about
given up thinking I'll ever get it to work.
 
J

Jonathan West

I can't think of any reason why the code wouldn't work for you. Close Word
and try again.

Also, show me the exact code that you are using.
 
S

Susan

IT WORKS!!!
Hurray!

Closing the Word program and restarting it made it work!

Thanks bunches.
 
J

Jean-Guy Marcil

Bonjour,

Dans son message, < Jonathan West > écrivait :
In this message, < Jonathan West > wrote:

|| I can't think of any reason why the code wouldn't work for you. Close
Word
|| and try again.
||
|| Also, show me the exact code that you are using.
||

Has language got anything to do with this?

On my French version of XP, I can't get it to work.

Those 2 lines

CommandBars("Clipboard").Visible = False
CommandBars("Clipboard").Visible = True

have no effect whatsoever.

And,

Sub Test()
CommandBars("Clipboard").Controls(4).Execute
End Sub

throws an error #9 (Index does not belong to the selection).

What am I missing?
TIA

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
J

Jonathan West

Jean-Guy Marcil said:
Bonjour,

Dans son message, < Jonathan West > écrivait :
In this message, < Jonathan West > wrote:

|| I can't think of any reason why the code wouldn't work for you. Close
Word
|| and try again.
||
|| Also, show me the exact code that you are using.
||

Has language got anything to do with this?

On my French version of XP, I can't get it to work.

Those 2 lines

CommandBars("Clipboard").Visible = False
CommandBars("Clipboard").Visible = True

have no effect whatsoever.

And,

Sub Test()
CommandBars("Clipboard").Controls(4).Execute
End Sub

throws an error #9 (Index does not belong to the selection).

What am I missing?
TIA


Does the Clipboard toolbar have a different name in the French version of
Word? If so, use that name instead.

Also, this does not work in Office XP or Office 2003, it only works in 2000
or 97. Thigs changed when the takbars were introduced.
 
J

Jean-Guy Marcil

Bonjour,

Dans son message, < Jonathan West > écrivait :
In this message, < Jonathan West > wrote:

|| ||| Bonjour,
|||
||| Dans son message, < Jonathan West > écrivait :
||| In this message, < Jonathan West > wrote:
|||
||||| I can't think of any reason why the code wouldn't work for you. Close
Word
||||| and try again.
|||||
||||| Also, show me the exact code that you are using.
|||||
|||
||| Has language got anything to do with this?
|||
||| On my French version of XP, I can't get it to work.
|||
||| Those 2 lines
|||
||| CommandBars("Clipboard").Visible = False
||| CommandBars("Clipboard").Visible = True
|||
||| have no effect whatsoever.
|||
||| And,
|||
||| Sub Test()
||| CommandBars("Clipboard").Controls(4).Execute
||| End Sub
|||
||| throws an error #9 (Index does not belong to the selection).
|||
||| What am I missing?
||| TIA
||
||
|| Does the Clipboard toolbar have a different name in the French version of
|| Word? If so, use that name instead.
||
|| Also, this does not work in Office XP or Office 2003, it only works in
2000
|| or 97. Thigs changed when the takbars were introduced.

Ha! The Word version wasn't explicitely stated in the thread... But the OP
mentioned
Microsoft Excel 9.0 Object Library
So she is using Word 2000...

Thanks.
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top