This won't work since OPENFILENAME is the typedef (don't worry about names just suffice it won't work)
Private Sub CommandButton5_Click()
GetFileName
TextBox2.Text = OPENFILENAME.lpstrfile
End Sub
This won't work since OpenFile is private AND contains all local variables
Private Sub CommandButton5_Click()
GetFileName
TextBox2.Text = OpenFile.lpstrfile
End Sub
This won't work since lpstrFile is not a member of GetFileName
Private Sub CommandButton5_Click()
GetFileName
TextBox2.Text = GetFileName.lpstrFile
End Sub
So, how do we make it all work .....
First - Redefine the Sub GetFileName as a function. To do this replace
Sub GetFileName()
with
Function GetFileName()
AND
End Sub
with
GetFileName = OpenFile.lpstrfile
End Function
Now whenever you call GetFileName do it like this...
Private Sub CommandButton5_Click()
TextBox2.Text = GetFileName
End Sub
Now that GetFileName is a Function it will return a value. That value will be the file name.
I will be adding code to allow you to select multiple files IF you want to but I have to work out the string parsing routine.
Daron, try this and see if it gives you the desired results in an array:
'declare a variable to hold the array
Dim FileNames() As String
Dim X As Integer
Dim Y as Integer
'grab the path put it in 0
Redim Preserve FileNames(0)
FileNames(0) = OpenFile.lpstrfile
Y = 1
'Calculate the length of the string, You may need to increase the length of the string in the call, by increasing 257 to 4096
'grab length of lpstrFile and look at each item
For X = 1 to Len(OpenFile.lpstrFile)
' If the current item is NULL
If Mid$(OpenFile.lpstrFile, X, 1) = String(1,0) Then
'Add an additional object to the array
Redim Preserve FileNames(Y)
'Increment past the NULL character and grab the remaining
' by default the string will be truncated at the NULL character
FileNames(Y) = Mid$(OpenFile.lpstrfile, (X + 1), Len(OpenFile.lpstrFile))
'increment the file counter
Y = Y + 1
End If
' check the next item
Next X
Daron, I worte this on the fly so how about testing it for me and see how it works....
It will only work with Flags set to 524800
Also you will need to have some error checking to make sure the filename array is not expanded for null entries.