Clipboard Problem using VBA

H

h.simonot

Hi everybody,

I've a stange behavior in my macro (Windows XP SP3, Office 2002 SP3) :

I try to copy and paste some text from a word document to another (from an excel VBA project).

I use this kind of code :
doc1.ActiveDocument.Content.Copy
....
doc2.Selection.Paste

It works most of the time...

But with some computers, instead of copying doc1 to doc2... It just paste a bitmap icon in doc2. I don't even know where does it come from !

Has somenone an idea ? I'm completely lost !
The most strange : if I put a break point after doc1.ActiveDocument.Content.Copy, and try to paste in another document, it works ! VBA Memory leak ?

Thanks a lot.
 
A

Auric__

h.simonot said:
I've a stange behavior in my macro (Windows XP SP3, Office 2002 SP3) :

I try to copy and paste some text from a word document to another (from
an excel VBA project).

I use this kind of code :
doc1.ActiveDocument.Content.Copy
...
doc2.Selection.Paste

It works most of the time...

But with some computers, instead of copying doc1 to doc2... It just
paste a bitmap icon in doc2. I don't even know where does it come from !

Has somenone an idea ? I'm completely lost !
The most strange : if I put a break point after
doc1.ActiveDocument.Content.Copy, and try to paste in another document,
it works ! VBA Memory leak ?

You could try clearing the clipboard before your code:

Declare Function CloseClipboard Lib "user32" () As Long
Declare Function EmptyClipboard Lib "user32" () As Long
Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long

Sub foo()
OpenClipboard 0
EmptyClipboard
CloseClipboard
doc1.ActiveDocument.Content.Copy
'...
doc2.Selection.Paste
End Sub

Don't know if that would solve your problem, though.
 

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