none
Prevent File Save Dialog appearing? RRS feed

  • Question

  • I have been using Excel 2010 to create Word Documents and then use .SaveAs to save the newly created file without any issues

    When I moved to Office 2013 the same code now presents a File Save dialog box.

    I have researched the issue and can find no way to prevent the Dialog appearing (and worse regardless of the user selection the Excel code crashes)

    The following is a simplified version of the troublesome code

    Sub TestWordSaveAs2()
    Dim InvoiceProFormaFileName As Variant
    Dim NewFileName As String
    Dim WordApplication As Object
    Dim WordDoc As Object

      ' Prompt for a word document
      InvoiceProFormaFileName = Application.GetOpenFilename(FileFilter:="Word Documents, *.docx", Title:="Any Word File", MultiSelect:=False)
      Set WordApplication = CreateObject("Word.Application")
      Set WordDoc = WordApplication.Documents.Open(InvoiceProFormaFileName) ' Open the pro-forma invoice

      ' Create a new name
      NewFileName = Replace(InvoiceProFormaFileName, ".docx", "2.docx")
     
      WordDoc.SaveAs2 Filename:=NewFileName, FileFormat:=16, AddtoRecentFiles:=False ' <======= this line Shows the File Save Dialog and then fails
     
      WordDoc.Close SaveChanges:=0 ' wdDoNotSaveChanges
     
      ' Finished with the Word Application so can close
      WordApplication.Quit
     
    End Sub

    Thank you in advance

    Tuesday, April 14, 2015 2:26 AM

All replies


  •   WordDoc.SaveAs2 Filename:=NewFileName, FileFormat:=16, AddtoRecentFiles:=False ' <======= this line Shows the File Save Dialog and then fails

    I can not reproduce the behavior, I guess the issue is related to the Word document.

    Do as follows:

    Open Word
    Make a new file
    Save the file as "Doc1.docx" on your local drive.
    Open Excel
    Make a new file
    Open the VBA editor
    Add a regular module
    Paste in your code and run it
    Select the "Doc1.docx" on your local drive.

    I can not see a SaveAs dialog.

    Andreas.

    Tuesday, April 14, 2015 5:39 AM
  • Andreas

    I followed your instructions but ended up with the same result

    After selecting Save or Cancel from the File Save Dialog Excel presents a Run-time error '4198': Command failed

    The File Save Dialog "ignores" the Filename and FileFormat parameters always presenting the original filename and word document options

    Any other thoughts?

    Martin

    Tuesday, April 14, 2015 11:20 PM
  • Hi,

    I have create a doc file and a excel file in my pc, after I run the code you have provided ,and choose the doc file I just created, it runs without any save dialog. And My Office is Pro Plus 2013 .

    I have upload my sample to OneDrive, you can download it here:

    http://1drv.ms/1DhnMe5

    When you run this sample, will this show the save dialog again ?

    To narrow down this issue, can you create a new empty word and choose it in the excel, does it will happen again? if it is convenient, can you share the doc file you're using? Have you update your office ?


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, April 15, 2015 9:32 AM
    Moderator
  • Exactly the same result ... with a File Save Dialog appearing ...

    Microsoft Windows 8.1

    Version 6.3.9600 Build 9600

    Excel 2013 (15.0.4701.1001) MSO (15.0.4701.1000) 32-bit

    Excel Updates shows Version 15.0.4701.1002

    Excel Visual Basic for Applications 7.1 Version 1044 Retail 7.1.1044 Forms3: 15.0.4687.100

    Word Updates Version 15.0.4701.1002

    I have already tried creating a blank document saving an running - same result as with the Invoice word file (that was created under 2010)

    I checked and there are NO MACROS in the Word Documents and Normal has not been altered in anyway

    Thursday, April 16, 2015 6:11 AM
  • Hi,

    Is there any other add-ins in your Word, can you please disable all these add-ins and run it again ?

    Best Regards

    Lan


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, April 17, 2015 10:13 AM
    Moderator
  • This is a new installation of Office 2013 and I have not installed any add ins

    To make sure I checked Word Add Ins and none are shown

    Any other suggestions why SaveAs and SaveAs2 do not work on this computer?

    Tuesday, April 21, 2015 5:48 AM