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!
 

Some videos you may like

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

dms37

Board Regular
Joined
Nov 29, 2006
Messages
231
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"
 

jaik22

Board Regular
Joined
Sep 23, 2016
Messages
102
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:

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
40,524
Office Version
365
Platform
Windows
try
Code:
ChDrive Left(ActiveWorkbook.Path, 2)
ChDir ActiveWorkbook.Path
SaveAsName = Application.GetSaveAsFilename(FileFilter:="Excel Files (*.xlsx), *.xlsx")
 

jaik22

Board Regular
Joined
Sep 23, 2016
Messages
102
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:

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
40,524
Office Version
365
Platform
Windows
Glad to help
 

Watch MrExcel Video

Forum statistics

Threads
1,098,857
Messages
5,465,099
Members
406,412
Latest member
superjoejoe

This Week's Hot Topics

Top