Home > database >  How to save as an excel workbook and open the saved workbook
How to save as an excel workbook and open the saved workbook

Time:08-30

I have the code below to save as an excel workbook. The problem I have is it saves it to the folder but does not continue with the saved file as the current open excel workbook.

With Application.FileDialog(msoFileDialogSaveAs)
    .Title = "Save schedules to specified folder"
    .ButtonName = "Save Schedules"
    .InitialFileName = "schedules"
    .Show
    Application.DisplayAlerts = False
    Application.EnableEvents = False
    End With

What I am trying to achieve is the same function as the save as in excel where you save and continue working with the saved document

CodePudding user response:

This program did not save the file. And the file should still be opened. I modify your program as

Application.DisplayAlerts = False
Application.EnableEvents = False
Dim fd As FileDialog
Set fd = Application.FileDialog(msoFileDialogSaveAs)
With fd
    .Title = "Save schedules to specified folder"
    .ButtonName = "Save Schedules"
    .InitialFileName = "schedules"
    .Show
End With
ActiveWorkbook.SaveAs fd.SelectedItems(1)
'wb1.SaveAs fd.SelectedItems(1)
'wb1.Activate
Application.DisplayAlerts = True
Application.EnableEvents = True

Then the file can be saved. You may need to select file type as xlsm to save without error. It may be better to add filters in Filedialog. If the workbook to save is not the activeworkbook, you can modify this part, maybe activate the workbook after saving, all up to you.

  • Related