GetSaveAsFilename Issues

pujo

Well-known Member
Joined
Feb 19, 2009
Messages
710
Office Version
  1. 2019
  2. 2013
Platform
  1. Windows
I am trying to save a daily report to its current directory.
It looks as it is saving correctly however, the file is not there...
Here is the logic I am using, I just can't figure it out!
I am pulling my hair out over this!

VBA Code:
Sub SaveDailyReport()
Dim S As Variant, MyName As String, fName() As String, fPath As String
Application.DisplayAlerts = False
MyName = Application.UserName
fName = Split(MyName, ",")
fPath = ActiveWorkbook.Path
  S = Application.GetSaveAsFilename(InitialFileName:=fPath & "\" & "Daily Report" & " - " & Format(Now(), "dd-mmm-yy"), FileFilter:="Excel Files (*.xlsb), *.xlsb")
    If S = False Then
      MsgBox ("Hey " & fName(1) & vbNewLine & "You canceled the save" & vbNewLine & _
      "Your data will be lost if you do not save!"), Buttons:=vbOKOnly + vbCritical, Title:="Save Canceled"
      Exit Sub
    End If
End Sub
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
When I Debug.Print S, It shows the correct folder path.
I just don't get it.....:mad:
 
Upvote 0
try this
VBA Code:
Sub SaveDailyReport()
Dim S As Variant, MyName As String, fName() As String, fPath As String
Application.DisplayAlerts = False
MyName = Application.UserName
fName = Split(MyName, ",")
fPath = ActiveWorkbook.Path
  S = Application.GetSaveAsFilename(InitialFileName:=fPath & "\" & "Daily Report" & " - " & Format(Now(), "dd-mmm-yy"), FileFilter:="Excel Files (*.xlsb), *.xlsb")
    ActiveWorkbook.SaveAs S
    If S = False Then
      MsgBox ("Hey " & fName(1) & vbNewLine & "You canceled the save" & vbNewLine & _
      "Your data will be lost if you do not save!"), Buttons:=vbOKOnly + vbCritical, Title:="Save Canceled"
      Exit Sub
    End If
End Sub
 
Upvote 0
Hi,

The answer to your issue is in the VBA Helpfile Application.GetSaveAsFilename method (Excel)

“Displays the standard Save As dialog box and gets a file name from the user without actually saving any files.”

You need to add a line of code to save the file

Rich (BB code):
Sub SaveDailyReport()
    Dim S             As Variant
    Dim MyName As String, fName() As String, fPath As String
    
    MyName = Application.UserName
    fName = Split(MyName, ",")
    fPath = ActiveWorkbook.Path
    S = Application.GetSaveAsFilename(InitialFileName:=fPath & "\" & "Daily Report" & " - " & Format(Now(), "dd-mmm-yy"), FileFilter:="Excel Files (*.xlsb), *.xlsb")
    
    If S = False Then
        MsgBox ("Hey " & fName(1) & vbNewLine & "You cancelled the save" & vbNewLine & _
               "Your data will be lost If you Do Not save!"), Buttons:=vbOKOnly + vbCritical, Title:="Save Cancelled"  
    Else
        'save workbook
        Application.DisplayAlerts = False
        ActiveWorkbook.SaveAs S, xlExcel12
    End If
    Application.DisplayAlerts = True
End Sub

Hope Helpful

Dave
 
Upvote 1
Solution
Don't I feel dumb....:rolleyes: I just missed it.
Appreciate the help!
 
Upvote 0
No worries we have all done it at sometime
Appreciate your feedback

Dave
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,333
Members
452,636
Latest member
laura12345

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