Dim filebox As OPENFILENAME ' open file dialog structure
Dim fname As String ' filename the user selected (gets complete path)
Dim result As Long ' result of opening the dialog (return value if file is found)
Dim dest As String ' constant path of where files will be uploaded
Dim arrFileArray() As String
Dim strFileString As String 'file name without path
' Configure how the dialog box will look
With filebox
' Size of the structure.
.lStructSize = Len(filebox)
' Handle to window opening the dialog.
.hwndOwner = Me.Hwnd
' Handle to calling instance (not needed).
.hInstance = 0
' File filters to make available: Text Files and All Files
.lpstrFilter = "All Files (*.*)" & vbNullChar & "*.*" & vbNullChar & vbNullChar
'.lpstrCustomFilter is ignored -- unused string
.nMaxCustomFilter = 0
' Default filter is the first one.
.nFilterIndex = 1
' No default filename. Also make room for received
' path and filename of the user's selection.
.lpstrFile = Space(256) & vbNullChar
.nMaxFile = Len(.lpstrFile)
' Make room for filename of the user's selection.
.lpstrFileTitle = Space(256) & vbNullChar
.nMaxFileTitle = Len(.lpstrFileTitle)
' Initial directory is C:\.
.lpstrInitialDir = "C:\" & vbNullChar
' Title of file dialog.
.lpstrTitle = "Select a File" & vbNullChar
' The path and file must exist; hide the read-only box.
.flags = OFN_PATHMUSTEXIST Or OFN_FILEMUSTEXIST Or OFN_HIDEREADONLY
' The rest of the options aren't needed.
.nFileOffset = 0
.nFileExtension = 0
'.lpstrDefExt is ignored -- unused string
.lCustData = 0
.lpfnHook = 0
'.lpTemplateName is ignored -- unused string
End With
' Display the dialog box.
result = GetOpenFileName(filebox)
If result <> 0 Then
'file found
' Remove null space from the file name.
fname = Left(filebox.lpstrFile, InStr(filebox.lpstrFile, vbNullChar) - 1)
Debug.Print "The selected file: "; fname
Else
'user wants to cancel
'MsgBox "Invalid File!", vbExclamation, "Invalid File"
Exit Sub
End If