SaveAs file name with new format in current folder

1.9k views Asked by At

I have setup the following macro in a Word Template to save my file to the place where the template is current saved, but in a sub-folder with a new name and file format. Each time I run the macro I get a "Command failed" Error.

Here is my code:

pathName = ActiveDocument.Path & "\Periodic Count\CaseManager_CSV.txt"
ActiveDocument.SaveAs fileName:=pathName, FileFormat:=wdFormatText
1

There are 1 answers

0
Kazimierz Jawor On BEST ANSWER

I think the reason of your problem stem from unsaved document which doesn't have a path. As a result your pathName variable value is only like this: "\Periodic Count\CaseManager_CSV.txt" which is incorrect.

As you mentioned you want to save in the subfolder of the folder where your template is saved. Possibly you should modify pathName variable in this way:

pathName = ActiveDocument.AttachedTemplate.Path & "\Periodic Count\CaseManager_CSV.txt"