get current workbook path for Application.GetSaveAsFilename vba

jaik22

Board Regular
Joined
Sep 23, 2016
Messages
102
I have code below to save my workbook file as WriteResPassword, but is there any way to get current workbook's path in the interface from
Application.GetSaveAsFilename? For now saving as interface displays document folder, so it requires 5-10 more clicks to get where I wanted.

Code:
Sub PasswordSave()Application.DisplayAlerts = FalseApplication.ScreenUpdating = False
SaveAsName = Application.GetSaveAsFilename( _FileFilter:="Excel Files (*.xlsx), *.xlsx")
ActiveWorkbook.SaveAs Filename:=SaveAsName, FileFormat:= _xlNormal, WriteResPassword:="test", ReadOnlyRecommended:=False _, CreateBackup:=False
End Sub

Anything helps!

Thank you!
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Put this before the SaveAsName. I haven't tested it but I use it for something I have for selecting files to open that uses GetOpenFilename(). My money is on it'll work here too.

ChDrive "C:"
ChDir "C:\folder location you want"
 
Upvote 0
Put this before the SaveAsName. I haven't tested it but I use it for something I have for selecting files to open that uses GetOpenFilename(). My money is on it'll work here too.

ChDrive "C:"
ChDir "C:\folder location you want"

Thanks for the reply. You are idea is great, but
I would like to setup dynamic location so I can use any location with this macro.
 
Last edited:
Upvote 0
try
Code:
ChDrive Left(ActiveWorkbook.Path, 2)
ChDir ActiveWorkbook.Path
SaveAsName = Application.GetSaveAsFilename(FileFilter:="Excel Files (*.xlsx), *.xlsx")
 
Upvote 0
Code:
Sub FinalizeReport()
Application.DisplayAlerts = False
Application.ScreenUpdating = False


ChDrive Left(ActiveWorkbook.Path, 2)
ChDir ActiveWorkbook.Path
SaveAsName = Application.GetSaveAsFilename(FileFilter:="Excel Files (*.xlsx), *.xlsx")
ActiveWorkbook.SaveAs Filename:=SaveAsName, FileFormat:= _
xlNormal, WriteResPassword:="test", ReadOnlyRecommended:=False _
, CreateBackup:=False




End Sub

Thank you so much for the support, but I am getting an error when I open up the saved file "The file format or file extension is no valid. Verify that the file has not been corrupted and that the file extension matches the format of the file".
Did I make any mistake on the code?

Thank you!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,528
Messages
6,120,065
Members
448,941
Latest member
AlphaRino

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