save csv file

M

muyBN

I used the following code in developing a macro under Word 2003 then put it
on a machine using Word 2007. Everything I've transferred from 2003 to 2007
macros has worked fine, but with the code below, 2007 gave me a message
saying the file didn't exist. Duh...that's why I'm using the Save As command,
so the file can be created. Any help on this?

ActiveDocument.SaveAs FileName:=strPath & "Mailing" & dtmFile &
".csv", FileFormat:=wdFormatText, _
LockComments:=False, Password:="", AddToRecentFiles:=True,
WritePassword:="", ReadOnlyRecommended:=False, _
EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False,
SaveFormsData:=False, SaveAsAOCELetter:= _
False, Encoding:=1252, InsertLineBreaks:=False,
AllowSubstitutions:=False, LineEnding:=wdCRLF
 
M

muyBN

I hope someone can please help me with this question and that hopefully it
hasn't been passed over. Is there a difference between the "Save As" command
in W2007 as compared to W2003?
 
G

Graham Mayor

The important part of the string is:

ActiveDocument.SaveAs FileName:=strPath & "Mailing" & dtmFile & ".csv",
FileFormat:=wdFormatText

and this will work just as well in 2007 as 2003 if the various parts of the
filename have been defined.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
M

muyBN

I agree that it SHOULD run under 2007, but it doesn't. The variables
representing the path and date components are correct, but it returns the
response that the file doesn't exist.
 
G

Graham Mayor

What file doesn't exist? The following works for me in both 2003 and 2007

strPath = "d:\My Documents\Test\"
dtmFile = "file"
ActiveDocument.SaveAs FileName:=strPath & "Mailing" & dtmFile & ".csv",
FileFormat:=wdFormatText

to create the file

D:\My Documents\Test\Mailingfile.csv

For testing try the following

strPath = "d:\My Documents\Test\"
dtmFile = "file"
sFilename = strPath & "MailingTest" & dtmFile & ".csv"
MsgBox sFilename
'ActiveDocument.SaveAs FileName:=sFilename, FileFormat:=wdFormatText

Does the messagebox show a valid path and filename?

Try instead

sFilename = Chr(34) & strPath & "MailingTest2" & dtmFile & ".csv" & Chr(34)

All of these work for me?

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - 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