Excel 2010 VBA SaveAs No dialog/Prompt

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!
antoniokingAsked:
Who is Participating?
 
ScriptAddictConnect With a Mentor Commented:
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
0
 
Rory ArchibaldCommented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.