ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   how set default path? (https://www.excelbanter.com/excel-programming/352284-re-how-set-default-path.html)

GS

how set default path?
 
Try this for v9+(2000 and later):

Application.Dialogs(xlDialogOpen).Show FullFilePathAndName, vbNormalFocus

GS


"Ian Elliott" wrote:

Thanks for any help.
I have a macro in a workbook that opens a workbook, gets some numbers out of
it, then opens another workbook, and puts the numbers in.
I could do this by hand, but there are about 15 numbers, and for once a day,
so I figure I can save some time by automating it.
The way I open the file is use getOpenFilename.
The thing is, everytime I run the macro, I have to change to the directory.
And the file I need is 4 or 5 folders down. Which takes a couple of seconds.
So I figure there is gotta be some way to set the default path so that when I
do the getOpenFilename method, it already shows the path I set in the code
just before that.
Here's the code:
...
MyFile = Application.GetOpenFilename("Microsoft Excel Application (*.xls),
*.mdb", , , , False)
Workbooks.Open MyFile
'get numbers
MyFile = Application.GetOpenFilename("Microsoft Excel Application (*.xls),
*.mdb", , , , False)
Workbooks.Open MyFile
'write numbers
I typically do this batch, for about 20 files one after another, so I only
have to set the folder the first time, but since I do the GetOpenFilename
method twice, each time I have to do about 5 or 6 clicks to get back to that
directory.
Is there someway to set the path so that when the dialog box opens, the path
is already set?
Another way I thought of doing this is not using getOpenFilename but
somekind of inputBox and a path, but I would like to try it this way.
Thanks again.


GS

how to set default path: -Correction
 
Correction: It should read as:

Application.Dialogs(xlDialogOpen).Show FullFilePath, vbNormalFocus

GS

"GS" wrote:

Try this for v9+(2000 and later):

Application.Dialogs(xlDialogOpen).Show FullFilePathAndName, vbNormalFocus

GS


"Ian Elliott" wrote:

Thanks for any help.
I have a macro in a workbook that opens a workbook, gets some numbers out of
it, then opens another workbook, and puts the numbers in.
I could do this by hand, but there are about 15 numbers, and for once a day,
so I figure I can save some time by automating it.
The way I open the file is use getOpenFilename.
The thing is, everytime I run the macro, I have to change to the directory.
And the file I need is 4 or 5 folders down. Which takes a couple of seconds.
So I figure there is gotta be some way to set the default path so that when I
do the getOpenFilename method, it already shows the path I set in the code
just before that.
Here's the code:
...
MyFile = Application.GetOpenFilename("Microsoft Excel Application (*.xls),
*.mdb", , , , False)
Workbooks.Open MyFile
'get numbers
MyFile = Application.GetOpenFilename("Microsoft Excel Application (*.xls),
*.mdb", , , , False)
Workbooks.Open MyFile
'write numbers
I typically do this batch, for about 20 files one after another, so I only
have to set the folder the first time, but since I do the GetOpenFilename
method twice, each time I have to do about 5 or 6 clicks to get back to that
directory.
Is there someway to set the path so that when the dialog box opens, the path
is already set?
Another way I thought of doing this is not using getOpenFilename but
somekind of inputBox and a path, but I would like to try it this way.
Thanks again.



All times are GMT +1. The time now is 09:32 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com