Frage

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
War es hilfreich?

Lösung

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"
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top