Code to open doc with today's date in name

E

Ed

I'm trying to write code into my macro that will open a document named with
today's date.

I have the following, but it doesn't seem to be working:

Dim FnmQueryA As String

Set FnmQueryA = (Now, "MMddyy") & "A"

Documents.Open FileName:=" C:\Nwaccess\Data\TIR Updates\ "FnmQueryA" &
".txt"



Any help is appreciated.



Ed
 
M

Malcolm Smith

Ed

I think that your string handling is a little awry:

Try this:

Documents.Open FileName:= "C:\Nwaccess\Data\TIR Updates\" _
& FnmQueryA & ".txt"


Of course it would be best to check that the file exists first, so perhaps
wrap it as such:


Dim sFileName as string

sFileName = "C:\Nwaccess\Data\TIR Updates\" & FnmQueryA & ".txt"
if len(dir$(sFileName)) > 0 then
Documents.Open sFileName
endif


Hope that this helps.
Malc
www.dragondrop.com
 
D

Doug Robbins - Word MVP

Hi Ed,

Use

Dim FnmQueryA As String

FnmQueryA = Format(Now, "MMddyy") & "A"

Documents.Open FileName:="C:\Nwaccess\Data\TIR Updates\"
& FnmQueryA & ".txt"

Please post any further questions or followup to the
newsgroups for the benefit of others who may be
interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting
basis.

Hope this helps
Doug Robbins - Word MVP
 

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