VBA Save As not Saving

Data Monkey

New Member
Joined
May 27, 2016
Messages
5
I've got some code that deletes a couple of tabs and then finished with a Save As box. Display Alerts is turned off for the second deleted tab (but I want it on for the first) but then turned back on before the Save As.

The Save As dialog box comes up and when I navigate to the desired file path (I don't want it specifying) I can see files in there but if I try to save over one of them it doesn't ask me if I want to like normal and it doesn't save.

Below is my code, please can someone let me know what I'm missing.

Code:
Sub Delete_Customer_Input()


    Application.ScreenUpdating = False
    Sheets("Customer Input").Delete
    Application.DisplayAlerts = False
    Sheets("Backup Data").Visible = True
    Sheets("Backup Data").Delete
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
    Sheets("Position Selection").Select
    Range("A1").Select
Dim varResult As Variant
'displays the save file dialog
varResult = Application.GetSaveAsFilename( _
    FileFilter:="Excel Macro-Enabled Workbook (*.xlsm), *.xlsm")
End Sub
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
As far as I'm aware, the GetSaveAsFilename() function will not prompt you if the destination file already exists. Note that this function will only retrieve a filename and not actually save the file. If you want to save the file (and get the overwrite prompt) then:

Code:
Sub Delete_Customer_Input()
    Application.ScreenUpdating = False
    Sheets("Customer Input").Delete
    Application.DisplayAlerts = False
    Sheets("Backup Data").Visible = True
    Sheets("Backup Data").Delete
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
    Sheets("Position Selection").Select
    Range("A1").Select
    Dim varResult As Variant
    Dim exitSub As Boolean
    Do
        exitSub = True
        ' Displays the save file dialog
        varResult = Application.GetSaveAsFilename(FileFilter:="Excel Macro-Enabled Workbook (*.xlsm), *.xlsm")
        If varResult = False Then
            ' Decide whether you want to re-prompt here
            exitSub = False ' This will re-prompt for the filename
        Else
            If exitSub Then
                On Error Resume Next
                Err.Clear
                ActiveWorkbook.SaveAs Filename:=varResult, FileFormat:=xlOpenXMLWorkbookMacroEnabled
                exitSub = Err.Number = 0
            End If
        End If
    Loop Until exitSub
End Sub

WBD
 
Upvote 0

Forum statistics

Threads
1,215,362
Messages
6,124,502
Members
449,166
Latest member
hokjock

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top