Using field codes to get date from file name

B

Barb Reinhardt

I have a file name with a date in it (FILENAME 051006.doc) and I want to
automatically update a section of the document with the date that's in the
file name. I've done something similar in Excel by parsing the file name.
Can this be done in Word using Field codes or something similar?

Thanks in advance,
Barb Reinhardt
 
T

Tony Jollans

In VBA you can get the file name from ActiveDocument.Name and can strip out
your date in many ways. One way ..

myWords = Split(Split(ActiveDocument.Name, ".")(0))
myDate = myWords(Ubound(myWords))

If you have done this in Excel you can probably use the same code in Word,
except for using ActiveDocument instead of ActiveWorkbook.

I'm not sure what you are asking about Fields.
 
B

Barb Reinhardt

Tony,

I've taken what you suggested and am trying to learn what else I need to do.
I'm not terribly experienced with VBA. I have this so far:

strDoc = ActiveDocument.Name
strDoc = "WE 050930 Report" <---testing with a known string

myWords = Split(strDoc, " ") <---Wrong number of arguments or invalid
property assignment

Dim i
For i = 0 To UBound(myWords)
Response.Write i & " = " & myWords(i) & "<BR>"
Next

What am I doing wrong.

Thanks!
 
T

Tony Jollans

Hi Barb,

I cut and pasted your code and the Split worked fine.

The Response.Write however isn't Word VBA,, and the "<BR"> makes me
suspicious. Where are you trying to run this?
 

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