Extract Partial File Name

armsys
2StarLounger
Posts: 105
Joined: 19 Apr 2010, 10:25
Location: Hong Kong

Extract Partial File Name

Post by armsys »

{filename} can be used to display the file name.
If the file names are in the "ABC 1234.docx" format, How can I extract the 4 numeric characters starting from the 5th character in the filename, namely, "1234"?
Thanks for your help.
Regards,
Armstrong

User avatar
HansV
Administrator
Posts: 78506
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Extract Partial File Name

Post by HansV »

Word doesn't offer any string manipulation functions in the interface, so I think you'll have to use VBA code. What do you want to do with the numeric characters?
Best wishes,
Hans

armsys
2StarLounger
Posts: 105
Joined: 19 Apr 2010, 10:25
Location: Hong Kong

Re: Extract Partial File Name

Post by armsys »

Hi HansV,
Long time no see, my old friend/teacher. Yes, {=} formulae patently lack all string manipulation functions. My objective is to extract and print the 4 digits from the filenames.
Exhibit 1200.docx
Exhibit 1201.docx
Exhibit 1202.docx
Exhibit 1203.docx
etc.
Thanks for your fast help.
Regards,
Armstrong

User avatar
HansV
Administrator
Posts: 78506
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Extract Partial File Name

Post by HansV »

"to extract and print the 4 digits from the filenames"

Does that mean that you want to process all docx files in a folder?
Best wishes,
Hans

armsys
2StarLounger
Posts: 105
Joined: 19 Apr 2010, 10:25
Location: Hong Kong

Re: Extract Partial File Name

Post by armsys »

Nope. It's much simpler. Just display the 4 digits of a docx file. It's intended as a cover sheet. Because there are many exhibits, manually typing the 4 digits is tideous and error-prone.
Regards,
Armstrong

User avatar
macropod
4StarLounger
Posts: 508
Joined: 17 Dec 2010, 03:14

Re: Extract Partial File Name

Post by macropod »

Hi Armstrong,

Since it's only the digits you're after, use a nested field coded as:
{={FILENAME} \# 0000}
Paul Edstein
[Fmr MS MVP - Word]

armsys
2StarLounger
Posts: 105
Joined: 19 Apr 2010, 10:25
Location: Hong Kong

Re: Extract Partial File Name

Post by armsys »

Hi Paul,
Thanks for your help. We're very close to the solution. For the Exhibit 1200.docx,
{={FILENAME} \# 0000} produces an error: !Syntax Error, 1200.
And why does it produce the period at the end?
At least it's the first time the doc filename can actually be manipuated.
Please help. Thanks.
Regards,
Armstrong

User avatar
HansV
Administrator
Posts: 78506
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Extract Partial File Name

Post by HansV »

Paul, I have a document named Doc 1234.docm.

I insert the following fields (field codes displayed):
FieldCodes.png
The result after hiding the field codes and updating the fields is:
NoFieldCodes.png
It does extract the number, but not quite in the way intended.

(I'm using Word 2010 SP1)
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans

armsys
2StarLounger
Posts: 105
Joined: 19 Apr 2010, 10:25
Location: Hong Kong

Re: Extract Partial File Name

Post by armsys »

Actually, Paul's solution works with a minor modification:
{quote {filename} \# 0000 }
Paul & hans, thanks for your help.
Regards,
Armstrong