我已经构建了一个程序来生成其他docm文件。该程序工作正常,而不通过VBA保存生成的文件。但是,当我使用SaveAs语句通过VBA保存时,生成的文件会损坏。尝试打开该文件会显示以下消息:
"Could not open the file, there is a problem with the contents."
SaveAs语句如下:
qDoc.SaveAs (getQuizURL(quizname))
quizUrl功能已经过全面测试并正常运行。
有谁知道造成这种情况的原因以及如何解决这个问题?我可以手动保存所有内容,但鉴于其他人将使用此程序,我希望尽可能使其友好。
答案 0 :(得分:1)
您缺少文件格式规范。
我不确定代码中的SaveAs
。
我有Office -2016,它有一个名为SaveAs2
的功能,但旧版本中可能有SaveAs
。
无论如何,更改代码以指定文件格式。
ThisDocument.SaveAs2 "C:\temp\Test.docm", WdSaveFormat.wdFormatXMLDocumentMacroEnabled
这样就可以了。