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
 

Some videos you may like

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

GTO

MrExcel MVP
Joined
Dec 9, 2008
Messages
6,154
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
 

JasonC71

Board Regular
Joined
Feb 10, 2008
Messages
159
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?
 

GTO

MrExcel MVP
Joined
Dec 9, 2008
Messages
6,154
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
 

JasonC71

Board Regular
Joined
Feb 10, 2008
Messages
159
Mark,

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

Thanks again for taking the time..

Jason
 

Watch MrExcel Video

Forum statistics

Threads
1,122,335
Messages
5,595,573
Members
413,996
Latest member
mabelO

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
Top