Directory browser in Excel VB

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

Mike Fogleman

I have an Excel workbook that consist of 3 sheets of forms to fill out.
These forms must be updated quarterly. I am going to use a database query to
pull the info needed into the workbook. The problem is for the user to
select the correct system and quarter for the query to update the forms.
The question is can I use VB to open the file directory browser and use his
selection to drive which database file to query? If so, what code is used to
accomplish this?
 
-----Original Message-----
I have an Excel workbook that consist of 3 sheets of forms to fill out.
These forms must be updated quarterly. I am going to use a database query to
pull the info needed into the workbook. The problem is for the user to
select the correct system and quarter for the query to update the forms.
The question is can I use VB to open the file directory browser and use his
selection to drive which database file to query? If so, what code is used to
accomplish this?


.

Yes - the Excel File Open dialog box can be activated
through VB:

FileToOpen = Application.GetOpenFileName ([File Filter],
[FilterIndex],[Title],[ButtonText],[MultiSelect])

FileToOpen will have the path to the selected file. The
parameters let you choose file extensions to show, etc.

(search the MSDN library for more info)
 
Database *file* suggests MS Access. If so, try this function:

Private Function GetJetDBName() As String
' Returns path & filename of user-selected Jet file
Dim vntFullFileName As Variant
Const WILDCARD_MSACCESS As String = "MS Access Databases (*.mdb), *.mdb"
Const TITLE As String = "Choose a Jet database file"
vntFullFileName = Excel.Application.GetOpenFilename(WILDCARD_MSACCESS, 1, TITLE)
If vntFullFileName = False Then
Exit Function
End If
GetJetDBName = CStr(vntFullFileName)
End Function
 
Back
Top