GetSaveAsFilename Method Question

JasonC71

Board Regular
Joined
Feb 10, 2008
Messages
159
Good Afternoon All!

I'm using the GetSaveAsFilename Method to grab a workbook path...when the file directory pops up for the user to navigate to the needed file, the directory defaults to show my documents...can I change that? I would like it to default to show the files in the folder that contains the workbook from which this code is running...

Can I do that? Does that make sense?

Thanks,

Jason
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Hi Jason,

Yes, that makes sense. Application.GetSaveAsFilename works about the same as if you select File|SaveAs, so if you want to change what directory (folder) is going to display, you'll want to try ChDir before you call GetSaveAsFilename.

Also - you may need to look at ChDrive if ThisWorkbook is in a different drive as MyDocuments.

Hope this helps,

Mark
 
Upvote 0
Thanks GTO,

One follow up if I may...if i use ChDir and set things to ThisWorkbook.Path (which is what I want)...is that a "permanent" thing...do I need to handle changing things back at the end of the routine or will the Directory revert back to the "factory setting" when I exit excel...and if I need to clean things up at the end of the routine..how do I find the "default" directory path?
 
Upvote 0
Greetings Jason,

ChDir does not do anything "permanent", and yes, next time you start Excel, the default filepath will be in effect.

A simple example:
Code:
Sub ex()
Dim strSaveAs As String
    '// If needed, change drive //
    ChDrive (Left(ThisWorkbook.Path, 1))
    ChDir ThisWorkbook.Path
    
    strSaveAs = Application.GetSaveAsFilename(InitialFilename:="MyFileName", _
                                FileFilter:="Excel Workbook (*.xls), *.xls", _
                                Title:="My Dialogue")
    
    If Not strSaveAs = "False" Then
    
        MsgBox "Save file etc"
        
    End If
    
End Sub

Hope thsi helps,

Mark
 
Upvote 0
Mark,

Thanks for the help. Things are now working perfectly...

Thanks again for taking the time..

Jason
 
Upvote 0

Forum statistics

Threads
1,213,534
Messages
6,114,184
Members
448,554
Latest member
Gleisner2

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