Excel 2010 VBA SaveAs No dialog/Prompt

Posted on 2012-09-05
Last Modified: 2012-10-09
I'm trying to my workbook using a macro, I don't want any prompts to show up.

I'm using the command...        
ActiveWorkbook.SaveAs Filename:=<FILEPATH>

Open in new window

However the save as dialog box is shown each time.

I've read about adding DisplayAlerts command before and after the saveas command
Application.DisplayAlerts = False
Application.DisplayAlerts = True

Open in new window

But the save as dialogue still keeps popping up!
Question by:antonioking
    LVL 11

    Accepted Solution

    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    Application.EnableEvents = False

      Dim vFile
      Dim strDirectoryPath As String
          If SaveAsUI Then
    vFile = Application.GetSaveAsFilename("C:\temp\Sample.xls", "Excel files (*.xls),*.xls")
       If TypeName(vFile) = "Boolean" Then
        Cancel = True
        Application.EnableEvents = True

           Exit Sub  ' user cancelled
    End If
       strDirectoryPath = "C:\temp\"
       If Dir(strDirectoryPath, vbDirectory) = "" Then MkDir strDirectoryPath

       ActiveWorkbook.SaveAs vFile, FileFormat:=56
       Application.EnableEvents = True
       saveProcessStarted = False
    Cancel = True
         Exit Sub
       End If
    Application.EnableEvents = True
     End Sub
    LVL 85

    Expert Comment

    by:Rory Archibald
    There is nothing in your code that would trigger a dialog unless your filename is missing or you are using a function to provide the file name.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Sometimes we don't want to show zeros in our Excel spreadsheets. This is sometimes most evident in our charts. Look at the chart below, all the zero values are visible. I think that all will agree with the fact that zero values are not looking nice …
    Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
    The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
    Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now