locked
Word 2016 command line switches /q not working any more? RRS feed

  • Question

  • Hi,


    With Word 2010 I was able to use a macro to export PDF from Word using the commandline:

    C:\Users\a_user>"C:\Program Files (x86)\Microsoft Office\Office14\WINWORD.EXE" /mExportToPDF /q "C:\folder\document.docm"




    When I try to run the same command for Word 2016, the PDF conversion does not work, and instead Word opens the document:

    C:\Users\a_user>"C:\Program Files (x86)\Microsoft Office\root\Office16\WINWORD.EXE" /mExportToPDF /q c:\folder\a_document.docm

    I cannot find any documentation about the command line switches in Office 2016, apart from some people mentioning problems: 

    • https://social.technet.microsoft.com/Forums/office/en-US/a01ac9a4-c170-4ff0-bd64-33d5bfe19d81/word-2016-no-longer-supports-the-n-command-line-switch?forum=word
    • https://social.technet.microsoft.com/Forums/en-US/8684da70-ef6c-4896-ac79-daa2be323d60/word-2016-no-longer-supports-the-r-command-line-switch?forum=word

    The old documentation does not mention Word 2016 at all: 

    https://support.microsoft.com/en-us/help/210565/how-to-use-startup-command-line-switches-to-start-word-2010,-word-2007,-word-2003,-word-2002,-and-word-2000

    my question: should the switches still work as before? Either they don't, or something else has changed, which I haven't figured out yet.

    with best regards,

    Philipp 


    • Edited by astrograph Monday, February 13, 2017 8:01 AM
    Monday, February 13, 2017 8:00 AM

All replies

  • Hi Philipp,

    Generally, the WinWord.exe /mmacro_name switch would start Word and then runs a specific macro. The /m switch also prevents Word from running any AutoExec macros.

    In your scenario, please try the following steps to confirm if your ExportToPDF macro is working fine in Word 2016:

    Open c:\folder\a_document.docm file manually in Word 2016, go to Developer tab (If there is no Developer tab in Word, go to File > Options > Customize Ribbon, check the Developer tab in Main Tabs list), click Macros, select the ExportToPDF macro, and click Run. Confirm if this file can be exported to PDF properly.

    If the Macro doesn't work in Word 2016 with Manual run in Developer tab, I think the issue may be related to your Macro codes. It is better to provide your detailed codes in Word for developers forum for more help:

    https://social.msdn.microsoft.com/Forums/office/en-US/home?forum=worddev


    Regards,

    Winnie Liang


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Tuesday, February 14, 2017 7:17 AM
  • Hello Winnie,

    thanks for the quick reply!

    I just ran the macro manually and it worked ok, it exported the document as a PDF and closed the application.

    When I try to run it from the commandline not only the /m switch doesn't seem to work, but also the /q switch.

    This is the macro: 

    Sub ExportToPDF()
        ChangeFileOpenDirectory ThisDocument.Path
    
        ActiveDocument.ExportAsFixedFormat _
            OutputFileName:="Some_Document.pdf", _
            ExportFormat:=wdExportFormatPDF, _
            OpenAfterExport:=False, _
            OptimizeFor:=wdExportOptimizeForPrint, _
            Range:=wdExportAllDocument, _
            From:=1, _
            To:=1, _
            Item:=wdExportDocumentContent, _
            IncludeDocProps:=True, _
            KeepIRM:=True, _
            CreateBookmarks:=wdExportCreateNoBookmarks, _
            DocStructureTags:=True, _
            BitmapMissingFonts:=True, _
            UseISO19005_1:=False
        Application.Quit SaveChanges:=wdSaveChanges
    End Sub
    

    with best regards,

    Philipp

    Wednesday, February 15, 2017 6:40 AM