PasteSpecial in VBA

D

Derek Hart

I want to use the pastespecial command in VBA to paste in a Microsoft Word
Document Object. The way I do this by hand is to highlight a file in Windows
Explorer, copy it to the clipboard, and choose Paste Special in Word. Then
it embeds a document. This way I do not have to worry about styles being
consistent and I can have a bunch of word docs inside one doc that can be
fully editable. When I record a macro I can get:

Selection.PasteSpecial Link:=False, DataType:=11, Placement:=wdInLine,
DisplayAsIcon:=False

Not sure what the DataType of 11 is, since help does not have a constant for
this. But I need a way to copy a Word doc to the clipboard so I can do this
in code. Is there a way?

Derek
 
J

Jezebel

You get the same result using Insert > Object and selecting the file. In
code, use:

ActiveDocument.Shapes.AddOLEObject Anchor:=Selection.Range, _
ClassType:=
"Word.Document", _
FileName:="C:\.......",
_
LinkToFile:=
False, _
DisplayAsIcon:=False
 
D

Derek Hart

A couple subtle differences exist when doing this. When I use the
PasteSpecial, I can get a clean Word icon for each document, but when using
the code, and switch the code to use an icon, I get a blank page for the
icon and the graphic is much bigger. Is there a way to get it working with
the same size icon and grahic used in PasteSpecial?

Derek
 
J

Jezebel

Interesting. I get *exactly* the same result either way: no blank page, same
size icon, using this code:

ActiveDocument.Shapes.AddOLEObject _
Anchor:=Selection.Range, _
ClassType:= "Word.Document", _
FileName:="C:\....", _
LinkToFile:= False, _
DisplayAsIcon:=True, _
IconFileName:=
"C:\WINDOWS\Installer\{90110409-6000-11D3-8CFE-0150048383C9}\wordicon.exe",
_
IconIndex:=1, _
IconLabel:="This is my file"
 

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