View Single Post
  #2   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson
 
Posts: n/a
Default Insert part of Filename in Header


If the name of the document is being set up by a macro at some point, i.e.
not on the user's machine, you should consider creating a Document Property
or Document Variable containing the text you want,and use a { DOCPROPERTY }
or { DOCVARIABLE } field to insert it in the header. NB, in older versions
of Word, { DOCVARIABLE } fields in the header used to crash Word.

Otherwise, it may be possible to do this but there are so many gotchas that
using a macro is probably safer and easier (and I say that with some
reluctance).

Precisely how to do it depends on the version of Word. In the current
version of Word 2003, you can get away with the following:

Create a .mdb file (if you don't have Access, you can create one by creating
a new mail merge list which is just a .mdb with a special format) or a .xls
file. There are other possibilities but this is the simplest approach. Let's
say you created c:\a\a.mdb.

Then insert the following nested field in your header

{ DATABASE \d "C:\\a\\a.mdb" \s "SELECT left('{ FILENAME }',instr('{
FILENAME } ',' ')-1)" }

(All the {} have to be the special field braces you can insert using
ctrl-F9, and all the single quotes need to be straight quotes. Note also the
doubled up backslashes in the file name, and the fact that there is a space
after the second { FILENAME } in case the filename has no spaces)

Gotchas include:
a. You have to distribute the .mdb But you do only need /one/ dummy .mdb
for all such applications.
b. The user may face security-related dialogs
c. If there are ever any single-quote characters in the filename, the field
will fail.

Peter Jamieson
"Wendy V" wrote in message
...
Is it possible to insert only part of a file name into the header? I have
a
document named "HSE-I.1-001-P HS&E Manual.doc" and I would like to insert
a
field that would display "HSE-I.1-001-P". I know I could accomplish this
using VBA but don't want the user to have to "enable macros" when they
open
the document. If I could insert this function:
mid(FILENAME,1,instr(FILENAME," ")) into the header it would accomplish
what
I want to do.

If anyone could offer any suggestions, I would really appreciate it.

Thanks,
Wendy