ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   vba browse button set to current directory (https://www.excelbanter.com/excel-programming/395496-vba-browse-button-set-current-directory.html)

ll

vba browse button set to current directory
 
I am working with a form with browse buttons to load a file from a
certain directory; I would like for that directory to be the one that
holds the currently open excel/vba form. Currently, I am using curdir
and getting the 'default' storage location set up in Excel
(MyDocuments..).

'=============
Dim SaveDriveDir As String
SaveDriveDir = CurDir()
MsgBox (CurDir)
ChDir (SaveDriveDir)
NewFN = Application.GetOpenFilename(FileFilter:="Excel Files
(*.xls), *.xls", Title:="Please select a file")
'===============


Thanks for any help in this,

Louis


Dan R.

vba browse button set to current directory
 
Louis,

CurDir = ThisWorkbook.Path
ChDir (CurDir)

--
Dan


Ron de Bruin

vba browse button set to current directory
 
Try this

Sub test()
Dim FName As Variant
Dim wb As Workbook
Dim MyPath As String
Dim SaveDriveDir As String

SaveDriveDir = CurDir

MyPath = ThisWorkbook.Path
ChDrive MyPath
ChDir MyPath

FName = Application.GetOpenFilename(filefilter:="Excel Files (*.xls), *.xls")
If FName < False Then
Workbooks.Open (FName)
End If

ChDrive SaveDriveDir
ChDir SaveDriveDir

End Sub


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"ll" wrote in message ups.com...
I am working with a form with browse buttons to load a file from a
certain directory; I would like for that directory to be the one that
holds the currently open excel/vba form. Currently, I am using curdir
and getting the 'default' storage location set up in Excel
(MyDocuments..).

'=============
Dim SaveDriveDir As String
SaveDriveDir = CurDir()
MsgBox (CurDir)
ChDir (SaveDriveDir)
NewFN = Application.GetOpenFilename(FileFilter:="Excel Files
(*.xls), *.xls", Title:="Please select a file")
'===============


Thanks for any help in this,

Louis



All times are GMT +1. The time now is 05:07 PM.

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