none
Word 2013 VBA - Document.SaveAs dialog appears even ApplicationClass.DisplayAlerts = WdAlertLevel.wdAlertsNone RRS feed

  • Question

  • Hi,

    The code has been working for many years. And with Word 2013, we have one case where the dialog will display when we try to save a document with VBA. Many of our Word 2013 runs without issue but just for a particular case, the save dialog comes up and then it throws an exception. Probably not related but we also tested with Office 365 and Office 2013 Pro. Only one client with Office 365 (Windows 8 - 32bit) does not work. Appreciate for your help in advanced!

    Here is the code:

                ApplicationClass WordAppl = new ApplicationClass();

                try
                {
                    WordAppl.DisplayAlerts = WdAlertLevel.wdAlertsNone;
                    object oWorkCopyDoc = Path.Combine(System.Windows.Forms.Application.StartupPath, "template.doc");
                    object oNewFileName2 = Path.Combine(System.Windows.Forms.Application.StartupPath, "result_" + DateTime.Now.ToFileTime() + ".doc");
                   
                    Document docResult = WordAppl.Documents.Open(ref oWorkCopyDoc, ref oNullValue, ref oFalseValue, ref oNullValue,
                        ref oNullValue, ref oNullValue, ref oNullValue, ref oNullValue, ref oNullValue, ref oNullValue,
                        ref oNullValue, ref oNullValue, ref oNullValue, ref oNullValue, ref oNullValue, ref oNullValue);

                    docResult.SaveAs(ref oNewFileName2, ref SaveFileFormatDOCX,
                        ref oNullValue, ref oNullValue, ref oNullValue, ref oNullValue,
                        ref oNullValue, ref oNullValue, ref oNullValue, ref oNullValue,
                        ref oNullValue, ref oNullValue, ref oNullValue, ref oNullValue,
                        ref oNullValue, ref oNullValue);
                    MessageBox.Show("Please check whether " + oNewFileName2 + " existed.");

                    docResult.Close(ref oFalseValue, ref oNullValue, ref oNullValue);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
                finally
                {
                    WordAppl.Quit();
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(WordAppl);
                }
    • Edited by Frank Lam Thursday, August 1, 2013 8:54 PM code as picture not appeared
    Thursday, August 1, 2013 8:19 PM

Answers

  • From all you tell me, my feeling is that there may be another third-party application (or a virus) mixing in - that the display of SaveAs is not coming from your application.

    This is difficult for you to test, since whatever it is is probably loading with Word. Best would probably be to comment out the line that starts the Word application and put in a line that starts a Word process using a commandline with the \a switch, that forces Word into safe mode. More information on starting Word from a commandline can be found here http://support.microsoft.com/kb/210565

    If this were VBA, it would be the Shell command. I'm not sure what the .NET equivalent is?


    Cindy Meister, VSTO/Word MVP, my blog

    Wednesday, August 7, 2013 12:55 PM
    Moderator

All replies

  • DisplayAlerts will not affect the saveAs dialog box. That's not an Alert - Alerts are warnings, error messages and similar.

    Exactly which line of code is triggering the display of the dialog box?

    For trouble-shooting, make sure that the Word.Application is visible so that you can see any messages Word might be displaying.


    Cindy Meister, VSTO/Word MVP, my blog

    Friday, August 2, 2013 11:52 AM
    Moderator
  • Hi Cindy,

    I have made WordAppl.visible = true at the top (and WdAlertLevel.wdAlertsAll). There is no other error message. The first thing it pops up is the SaveAs dialog box.

    Are there any area I should focus on?

    Franklin


    • Edited by Frank Lam Tuesday, August 6, 2013 7:13 PM
    Tuesday, August 6, 2013 6:59 PM
  • From all you tell me, my feeling is that there may be another third-party application (or a virus) mixing in - that the display of SaveAs is not coming from your application.

    This is difficult for you to test, since whatever it is is probably loading with Word. Best would probably be to comment out the line that starts the Word application and put in a line that starts a Word process using a commandline with the \a switch, that forces Word into safe mode. More information on starting Word from a commandline can be found here http://support.microsoft.com/kb/210565

    If this were VBA, it would be the Shell command. I'm not sure what the .NET equivalent is?


    Cindy Meister, VSTO/Word MVP, my blog

    Wednesday, August 7, 2013 12:55 PM
    Moderator