Reputation: 53
I am trying to get this code to save to the directory where the file was opened. At current it manages to save the file by cel text but by default wants to save in c:/my documents.
This is what i have so far and have no idea where to add ThisWorkbook.Path
Sub Save()
Dim flToSave As Variant
Dim flName As String
Dim flFormat As Long
flFormat = ActiveWorkbook.FileFormat
flName = Range("A1") & Range("A2").Text
flToSave = Application.GetSaveAsFilename _
(flName, filefilter:="Excel Files (*.xlsm), *.xlsm", _
Title:="Save FileAs...")
If flToSave = False Then
Exit Sub
Else
Thisworkbook.SaveAs Filename:=flToSave, FileFormat:=flFormat
End If
End Sub
Upvotes: 4
Views: 2193
Reputation: 53136
Change your GetSaveAsFilename
to
flToSave = Application.GetSaveAsFilename _
(ThisWorkbook.Path & "\" & flName, filefilter:="Excel Files (*.xlsm), *.xlsm", _
Title:="Save FileAs...")
This starts the SaveAs
in the specified directory
Upvotes: 1