Log in

View Full Version : Pastespecial as Picture(Enhanced Metafile)



paddysheeran
10-18-2010, 09:18 AM
Hi All,

Im currently writing some code to copy tables fom excel into word. When doing this manually I currently use the PasteSpecial > Picture (Enhanced Metafile) but I cant find the code anywhere for this after a lot of searching on the net. Does anyone have a quick solution for this. The current code I'm using which is not working is:

Sub WR_Response_Time()
Set wsSource = ActiveWorkbook.Sheets("Response Time")

Set t = wdDoc.Bookmarks("ResponseTime_ResponseTime").Range
wsSource.Activate
Set Rng = Range("B4:R10")
Rng.Copy
t.PasteSpecial DataType:=wdPasteEnhancedMetafile

End Sub

thanks in advance.

paddy.

fumei
10-18-2010, 12:06 PM
Can you tell us what is "not working"?

Sub yaddaPaste()
Dim r As Range
Set r = ActiveDocument.Bookmarks("blah").Range
r.PasteSpecial datatype:=wdPasteEnhancedMetafile
End Sub
works for me.

You do not seem to be declaring your variables. What is t? It MUST be declared as Word.Range.

paddysheeran
10-19-2010, 03:02 AM
The variables are declared in a previous sub that leads onto this one.

The code runs through fine but the final picture of the table from excel is small and does not pan the length of the page like it does when the process is completed manually.

fumei
10-19-2010, 10:34 AM
So t and wsSource are global (Public) variables?

I can not duplicate the problem. It works for me.

paddysheeran
10-20-2010, 04:42 AM
attached should show what I mean....

paddysheeran
10-20-2010, 04:44 AM
and yes the variables are public.

paddysheeran
10-20-2010, 05:24 PM
Solved it. The following needs to be applied:

t.PasteSpecial DataType:=wdPasteEnhancedMetafile, Placement:=wdInLine

fumei
10-21-2010, 08:54 AM
Thanks for posting the solution. I am guessing Placement must be a default.