Copy from Word into Excel pastes wrong picture

G

Guest

I've got a macro that parses through a Word document and copies and pastes
tables and figures into an Excel workbook. We've got a weird intermittent
bug where the wrong picture is pasted into Excel. (We're using Office 2000.)
It's pasting the same image twice in a row, even though different images are
being copied in Word. It's almost like the clipboard hasn't had a chance to
refresh between the copy and the paste command--as if the first image is
still on the clipboard and the new one hasn't made it to the clipboard yet.

The code is in a Word Template. Here's a code snippet:

Private mobjCurrentSheet As Excel.Worksheet
Private mobjExcelApp As Excel.Application

-- there's a bunch of code that scans down the document. when it finds a
picture, it does this: --
Selection.Paragraphs(1).Range.Copy

mobjExcelApp.ActiveCell.Offset(1, 0).Activate
mobjCurrentSheet.Paste




I tried putting this for loop in between the copy and the paste, but that
didn't help.
For i = 0 To 1000
DoEvents
Next i


As I mentioned, the bug is intermittent. Most of the time it works fine,
but it happens fairly requlary. I make sure I'm not doing anything else on
the PC while my code is running, so it can't be due to me trying to do a copy
and paste operation in my email app (for example) while the macro is running
in the background.

Does anyone have any ideas? Has anyone ever seen this type of behavior
before?

Thanks in advance for the help.
 
W

Wei Lu [MSFT]

Hello Luggage,

I would like to suggest you clear the Windows Clipboard before you copy the
objects from word.

You could refer the following KB article in your code to clear the
clipboard:

How To Call Clipboard API from Visual Basic 4.0
http://support.microsoft.com/kb/159823

Hope this helps.

Sincerely,

Wei Lu
Microsoft Online Community Support

==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 

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