Shauno-
Normally, I would suggest that you use a common dialog box control in a
form, but I am not sure that it is available in VBA. But you can copy paste
the code below in a separate module and then you will have a GetXMLFilePath
funtion at your disposal. Then you can use it like:
myXmlFilePath = GetXmlFilePath("Please browse to the XML file")
Here's the code:
----------------------------------
Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _
"GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
Private Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
strFilter As String
strCustomFilter As String
lMaxCustFilter As Long
lFilterIndex As Long
strFile As String
lMaxFile As Long
strFileTitle As String
lMaxFileTitle As Long
strInitialDir As String
strTitle As String
lFlags As Long
iFileOffset As Integer
iFileExtension As Integer
strDefExt As String
lCustData As Long
lpfnHook As Long
strTemplateName As String
End Type
Private Function GetFilePath(Filter As String, Title As String, Optional
DefaultDir As String) As String
Dim OpenFile As OPENFILENAME
Dim lReturn As Long
Dim sFilter As String
Dim i As Integer
OpenFile.lStructSize = Len(OpenFile)
'OpenFile.hwndOwner = Application.h
OpenFile.hInstance = 0
OpenFile.strFilter = Filter
OpenFile.lFilterIndex = 1
OpenFile.strFile = String(257, 0)
OpenFile.lMaxFile = Len(OpenFile.strFile) - 1
OpenFile.strFileTitle = OpenFile.strFile
OpenFile.lMaxFileTitle = OpenFile.lMaxFile
If IsMissing(DefaultDir) Or (DefaultDir = "") Then
OpenFile.strInitialDir = CurDir
Else
OpenFile.strInitialDir = DefaultDir
End If
OpenFile.strTitle = Title
OpenFile.lFlags = 0
lReturn = GetOpenFileName(OpenFile)
If lReturn = 0 Then
GetFilePath = ""
Else
i = InStr(OpenFile.strFile, vbNullChar)
If i > 0 Then
GetFilePath = Left(OpenFile.strFile, i - 1)
Else
GetFilePath = OpenFile.strFile
End If
End If
End Function
Function GetXMLFilePath(Title As String, Optional Path As String) As String
GetXMLFilePath = GetFilePath("XML (*.xml)" & Chr(0) & "*.xml" & Chr(0),
Title, Path)
End Function