File folder dialog

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

How do I open a file/folder dialog in a macro? I would like to start the
macro then be able to point to the folder that contains my excel files?

Thanks
Mike
 
MyFile=Application.GetOpenFileName
??
This doesn't open the file, but returns the full path of the file pointed to
(or False if cancel clicked). Then you open the file via
Workbooks.Open MyFile
....

Bob Umlas
Excel MVP
 
Hi Mike,

Take a look at the Application.GetOpenFilename method and see if that does
what you need. It provides a UI for the user to browse and select files,
and then returns the file for your macro to process as desired.

For information and sample code for integrating Office with Visual Basic,
Visual C++, Internet Scripts, and other programming languages, please see
http://msdn.microsoft.com/library/techart/VSOfficeDev.htm. This site
contains the most up-to-date information for using developer tools for
Office integration and extensibility.

Best regards,
Steve Danielson
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.

Are you secure? Please visit the Microsoft Security & Privacy Center
(http://www.microsoft.com/security) for the latest news on security updates.
 
Hi Mike,

I forgot to also mention:

Application.Dialogs(xlDialogOpen).Show

Take a look at the Application.Dialogs collection in the Visual Basic
Reference for Excel for more details on this and also
Application.GetOpenFilename.

For information and sample code for integrating Office with Visual Basic,
Visual C++, Internet Scripts, and other programming languages, please see
http://msdn.microsoft.com/library/techart/VSOfficeDev.htm. This site
contains the most up-to-date information for using developer tools for
Office integration and extensibility.

Best regards,
Steve Danielson
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.

Are you secure? Please visit the Microsoft Security & Privacy Center
(http://www.microsoft.com/security) for the latest news on security updates.
 
Thanks for your replies.

I have
..LookIn = "C:\my excel path"
It is hard coded in. How do I get the path programatically?

Thanks
Mike
 
That's not it after all.

I have this
ThisFolder = CurDir()
MsgBox (ThisFolder)
and it is not giving me the folder that the excel file that ran the macro is
in?? It gives me my desktop. How do I get the current folder the file is
in?

Mike
 
Try:

ThisFolder = ActiveWorkbook.Path

If the workbook has been saved, this will give the folder in which it is
saved. You don't need to use ActiveWorkbook if you have a reference already
to the workbook for which you wish to receive the path.

There is also an Application.Path property which gives the path to where
the application is run from.

Are you wanting the folder of a specific workbook that you load or some
other folder?

Steve

For information and sample code for integrating Office with Visual Basic,
Visual C++, Internet Scripts, and other programming languages, please see
http://msdn.microsoft.com/library/techart/VSOfficeDev.htm. This site
contains the most up-to-date information for using developer tools for
Office integration and extensibility.

Best regards,
Steve Danielson
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.

Are you secure? Please visit the Microsoft Security & Privacy Center
(http://www.microsoft.com/security) for the latest news on security updates.
 
The requested "the folder that the excel file that ran the macro is in" is actually

ThisWorkbook.Path
 
Back
Top