none
"Command failed" error '4198' at ActiveDocument.SaveAs in Word 2007 vba RRS feed

  • Question

  • The VBA macro below is generated after recording a macro using Word 2007 and it worked fine - i.e. creating a macro-enabled word template (test.dotm). However, if I use the same VBA code (macro) without recording it, I get the error as "Command failed error '4198'". Could you please help in this regard? The code is as follows:

    Sub Macro1()
    '
    ' Macro1 Macro
    '
    '
        ChangeFileOpenDirectory "C:\"
        ActiveDocument.SaveAs FileName:="test.dotm", FileFormat:= _
            wdFormatXMLTemplateMacroEnabled, LockComments:=False, Password:="", _
            AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=False, _
            EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, SaveFormsData _
            :=False, SaveAsAOCELetter:=False
    End Sub

    Kind regards,

    Misbah

    Tuesday, February 21, 2012 5:30 PM

Answers

  • Thank you for your reply. Infact, I have figured out myself. I was saving the active document (the one that contained the macro) as "*.dotm" (i.e. macro-enabled word template) instead of saving another (or new) file. The macro worked, if I save another file (or any other other opened file) as ".dotm". Thank you all for your help.

    Kind regards,

    Misbah

    • Proposed as answer by danishani Tuesday, February 28, 2012 3:26 PM
    • Marked as answer by Bruce Song Thursday, March 1, 2012 8:40 AM
    Tuesday, February 28, 2012 12:16 PM

All replies

  • Does it make a difference if you save to a different path? Saving to the root of C: is not always permitted.

    Regards, Hans Vogelaar

    Tuesday, February 21, 2012 8:26 PM
  • Thank you for your reply. Regardless of wherever, I'm saving the file, the macro gives the same "Command failed" error. I tried saving elsewhere to no avail. Also, it would be surprising, if it would have worked by saving to some other directory because, if one could save "*.xltm", "*.pptm" files to the root of C: by using the same "SaveAs" method in Excel and PowerPoint VBA respectively then, why does it not work for Word VBA. Looking forward and would be thankful for a solution.

    Regards,

    Misbah

    Friday, February 24, 2012 3:52 PM
  • Try taking the ".dotm" off the FileName property.  Just rely on the FileFormat property to establish the format.

    Kind Regards, Rich ... http://greatcirclelearning.com

    Friday, February 24, 2012 6:07 PM
  • Thank you for your reply. Infact, I have figured out myself. I was saving the active document (the one that contained the macro) as "*.dotm" (i.e. macro-enabled word template) instead of saving another (or new) file. The macro worked, if I save another file (or any other other opened file) as ".dotm". Thank you all for your help.

    Kind regards,

    Misbah

    • Proposed as answer by danishani Tuesday, February 28, 2012 3:26 PM
    • Marked as answer by Bruce Song Thursday, March 1, 2012 8:40 AM
    Tuesday, February 28, 2012 12:16 PM