GetSaveAsFilename Problem

esential

New Member
Joined
Oct 6, 2009
Messages
12
Hello,

I need in the end of a macro to SaveAs the file in a defined path, but the name of the new .xls file to be defined by the code. I just want to check the name of the new file and click save button, not to do more than that.
Now the code is working corectly, but when the SaveAs Popup appears the name of the file is blank and I have to write it.

You have the code below:

Code:
Sub FileSaveAs()    Dim file_name As Variant
    Dim FName, Number, Data, Name As String

    Number = "035"
    Data = Format(Date, "dd/mm/yyyy")
    Name = "Adrian"
    FName = "ABT" & Mid(Number, 2) & " " & Data & " - " & Name

    ChDir "C:\Users\Cipri Dia\Dropbox\"
     ' Get the file name.
    file_name = Application.GetSaveAsFilename(FName, _
    FileFilter:="Excel Files,*.xls,All Files,*.*", _
    Title:="Save As File Name")
     ' See if the user canceled.
    If file_name = False Then Exit Sub
     ' Save the file with the new name.
    If LCase$(Right$(file_name, 4)) <> ".xls" Then
        file_name = file_name & ".xls"
    End If
    ActiveWorkbook.SaveAs Filename:=file_name
End Sub


This is strange because if I put in a single macro is working good, if I put this code combined with another macro it appear the problem mentioned above.

Thank you!
 
Last edited:

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

Forum statistics

Threads
1,203,101
Messages
6,053,530
Members
444,670
Latest member
laurenmjones1111

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