How to EMBED a DOC via VB?

D

Dennis

I need to know the exact syntax of the Fields.Add method,
in order to EMBED a Word 2002 doc into another. Thanks!
 
J

Jezebel

expression.Add(Range, Type, Text, PreserveFormatting)

Why not just check Help for this sort of information?
 
G

Guest

Have you tried it? I have, and the syntax you describe
forks fine for a fieldtype of wbFieldLink. But when I use a
type of "wdFieldEmbed", I get "bad parameter", even after
adjusting the text content for what I believe it needs.
Hence my question. (BTW, I've been a developer for 30+
years, and I *do* know how to use the HELP facility. It is
not revealing in this case. I've spent hours reading
through it.)

Dennis
 
J

Jean-Guy Marcil

Bonjour,

Dans son message, < (e-mail address removed) > écrivait :

|| Have you tried it? I have, and the syntax you describe
|| forks fine for a fieldtype of wbFieldLink. But when I use a
|| type of "wdFieldEmbed", I get "bad parameter", even after
|| adjusting the text content for what I believe it needs.
|| Hence my question. (BTW, I've been a developer for 30+
|| years, and I *do* know how to use the HELP facility. It is
|| not revealing in this case. I've spent hours reading
|| through it.)
||
|| Dennis
||

Well, it seems to me Jezebel gave a very appropriate answer for the question
that was originally posted.

<quote>
I need to know the exact syntax of the Fields.Add method,
in order to EMBED a Word 2002 doc into another. Thanks!
<end quote>

You have to admit that you were not overly zealous in providing details
conducive to a helpful response. No?
We could not guess from your question that you had already tried and was
looking to solve a very specific problem.

It would still be helpful if you posted the relevant part of your code.

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

Dennis

If fs.FileExists(extractedFilePath) Then
Set myField = wordDoc.Fields.Add(Range:=myRange,

Type:=wdFieldEmbed, _
Text:=extractedFilePath, _
PreserveFormatting:=True)
End If

Where - extactedFilePath is the path and filename, and
myRange is a set to a Word Perfect INCLUDE statement that I
intend to replace with the EMBED.

When I use a field type of LINK, it works fine, but when I
switch to EMBED, I get a "bad parameter".

Thanks

Dennis
 
J

Jean-Guy Marcil

Bonjour,

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

| If fs.FileExists(extractedFilePath) Then
| Set myField = wordDoc.Fields.Add(Range:=myRange,
|
| Type:=wdFieldEmbed, _
| Text:=extractedFilePath, _
| PreserveFormatting:=True)
| End If
|
| Where - extactedFilePath is the path and filename, and
| myRange is a set to a Word Perfect INCLUDE statement that I
| intend to replace with the EMBED.
|
| When I use a field type of LINK, it works fine, but when I
| switch to EMBED, I get a "bad parameter".
|
| Thanks
|
| Dennis
|
|

A simple thing to check first, if this turns out to be the answer, then it
will save us both lots of time!

Are you making sure that "extactedFilePath" contains a path with double
"\\"? As in:
D:\\My Documents\\Test.Doc
and not
D:\My Documents\Test.Doc
?

Paths in word fields usually requires double \\. I guess this is to
distinguish between the \ used for parameters settings, as in \# for
defining numerical format for example. So, if you have something like:
D:\My Documents\Test.Doc
Word is trying to interpret \My as a switch, thus the bad parameter error
message.

Well, this is just my guess!

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

Dennis

Yes, the extracted path name DOES use the double "\\"
chars. (First thing I checked.)

Thanks!

Dennis
 
J

Jean-Guy Marcil

Bonjour,

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

| Yes, the extracted path name DOES use the double "\\"
| chars. (First thing I checked.)
|

It turns out you cannot create an EMBED field as you are trying to do:
From the Microsoft Office Online site:

{EMBED ClassName [Switches] }
Inserts an object created in another application that supports OLE (OLE: A
program-integration technology that you can use to share information between
programs. All Office programs support OLE, so you can share information
through linked and embedded objects.). Microsoft Word inserts the EMBED
field when you insert objects- such as Microsoft Excel worksheet objects- by
using the Object command (Insert menu), the Paste Special command (Edit
menu), or a toolbar (toolbar: A bar with buttons and options that you use to
carry out commands. To display a toolbar, click Customize on the Tools menu,
and then click the Toolbars tab.) button.
The EMBED field isn't available in the Field dialog box, and you cannot
manually insert the field. However, you can directly modify switches in an
existing EMBED field.
Instructions
ClassName
The name of the container application, such as Microsoft Excel. You cannot
modify this instruction.
Switches
\* MERGEFORMAT
Applies the sizing and cropping of the previous result to the new result. To
preserve previously applied sizing and cropping when you update the field,
don't delete this switch from the field.
Examples
The following field displays a Microsoft Graph object embedded (embed: To
insert information created in one program, such as a chart or an equation,
into another program. After the object is embedded, the information becomes
part of the document. Any changes you make to the object are reflected in
the document.) in a document:
{ EMBED MSGraph.Chart.8 \* MERGEFORMAT }

What you can try though is:
INCLUDETEXT
as in:

'_______________________________________
Set myField = WordDoc.Fields.Add(Range:=myRange, _
Type:=wdFieldEmpty, _
Text:="INCLUDETEXT " & extractedFilePath)
'_______________________________________

or add an OLE object,
as in:

'_______________________________________
myRange.InlineShapes.AddOLEObject ClassType:="Word.Document.8", _
FileName:=extractedFilePath, LinkToFile:=True, DisplayAsIcon:=False
'_______________________________________

--
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