문제

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
도움이 되었습니까?

해결책

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"
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top