Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Mailmerge and Fax / May 2006

Tip: Looking for answers? Try searching our database.

Insert part of Filename in Header

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Wendy V - 26 Apr 2006 16:17 GMT
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
Peter Jamieson - 26 Apr 2006 17:02 GMT
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
> Is it possible to insert only part of a file name into the header? I have
> a
[quoted text clipped - 12 lines]
> Thanks,
> Wendy
Wendy V - 01 May 2006 19:24 GMT
Peter,

Thanks so much for responding to my post and I apologize for the late
response.

I tried the .mdb method and it worked great when the field was inserted in
the main body of my document. However, I when I inserted the field into a
table I received the following error: "Error! Not a valid result for table."
Is there any way to fix this error (other than not inserting the field in a
table) or is this just a limitiation of Word?

Thanks
Wendy

> 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
[quoted text clipped - 48 lines]
> > Thanks,
> > Wendy
Peter Jamieson - 01 May 2006 19:51 GMT
Yes, it won't work in a table. I don't know why. But it works in a header
(as per your original post). Can a table be avoided?

Peter Jamieson

> Peter,
>
[quoted text clipped - 78 lines]
>> > Thanks,
>> > Wendy
Wendy V - 01 May 2006 21:23 GMT
I figured out that if I put the field in a text box, it the field displays
properly. I then overlayed the text box on top of the position in the table
where I need the resulting field information. Works great.

Thanks for your help!

> Yes, it won't work in a table. I don't know why. But it works in a header
> (as per your original post). Can a table be avoided?
[quoted text clipped - 83 lines]
> >> > Thanks,
> >> > Wendy
Wendy V - 01 May 2006 22:53 GMT
Just wondering if you know why this field (in the text box) will not update
unless I manually press F9. I have "Update Fields" selected in Options. Do I
need to use a macro? If so, how would I capture the "Save" event and update
just before the save? ( I wasn't sure if I should post this question in
another forum or in this one for continuity.)

Thanks,
Wendy

> Yes, it won't work in a table. I don't know why. But it works in a header
> (as per your original post). Can a table be avoided?
[quoted text clipped - 83 lines]
> >> > Thanks,
> >> > Wendy
Peter Jamieson - 01 May 2006 23:30 GMT
Two possibilities off the top of my head:
a. a lot of fields behave differently in text boxes (if they behave at all)
b. it could be to do with the security-related registry settings described
in

http://support.microsoft.com/kb/330554/en-us

which also apply to Word 2003 (except you need to adjust the version numbers
in the relevant registry paths.

Peter Jamieson
> Just wondering if you know why this field (in the text box) will not
> update
[quoted text clipped - 102 lines]
>> >> > Thanks,
>> >> > Wendy
Wendy V - 02 May 2006 14:52 GMT
Thank you, thank you! that link to the MS article did the trick.

> Two possibilities off the top of my head:
>  a. a lot of fields behave differently in text boxes (if they behave at all)
[quoted text clipped - 113 lines]
> >> >> > Thanks,
> >> >> > Wendy
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.