SwissMiss said:
Same problem. Multi select doesn't work. Copied in all the code. How
did you get it to work finally. Please respond. really desparate.
Thanks
Here's a version of the sample "GetOpenFile" function named
"GetOpenFileMulti", modified to do multiselect, along with a modified
version of the TrimNull function that is necessary for this to work, and
a demo function to call it, named "TestMultiselect":
'----- start of code -----
Function GetOpenFileMulti(Optional varDirectory As Variant, _
Optional varTitleForDialog As Variant) As Variant
' Here's an example that gets an Access database name.
Dim strFilter As String
Dim lngFlags As Long
Dim varFileName As Variant
Dim varFileList() As String
' Specify that the chosen file must already exist,
' don't change directories when you're done
' Also, don't bother displaying
' the read-only box. It'll only confuse people.
lngFlags = _
ahtOFN_FILEMUSTEXIST Or _
ahtOFN_HIDEREADONLY Or _
ahtOFN_NOCHANGEDIR Or _
ahtOFN_ALLOWMULTISELECT Or _
ahtOFN_EXPLORER
If IsMissing(varDirectory) Then
varDirectory = ""
End If
If IsMissing(varTitleForDialog) Then
varTitleForDialog = ""
End If
' Define the filter string and allocate space in the "c"
' string Duplicate this line with changes as necessary for
' more file templates.
strFilter = ahtAddFilterItem(strFilter, _
"Access (*.mdb)", "*.MDB;*.MDA")
' Now actually call to get the file name.
varFileName = ahtCommonFileOpenSave( _
OpenFile:=True, _
InitialDir:=varDirectory, _
Filter:=strFilter, _
flags:=lngFlags, _
DialogTitle:=varTitleForDialog)
GetOpenFileMulti = varFileName
End Function
Public Function TrimNull(ByVal strItem As String) As String
Dim intPos As Integer
intPos = InStr(strItem & vbNullChar & vbNullChar, _
vbNullChar & vbNullChar)
If intPos > 0 Then
TrimNull = Left(strItem, intPos - 1)
Else
TrimNull = strItem
End If
End Function
Public Function TestMultiselect()
Dim strFiles As String
Dim astrFiles() As String
Dim i As Integer
strFiles = GetOpenFileMulti(, "Ctrl-Click for Multi-Select")
astrFiles = Split(strFiles, vbNullChar)
If UBound(astrFiles) < LBound(astrFiles) Then
Debug.Print "No files were selected"
ElseIf UBound(astrFiles) = LBound(astrFiles) Then
Debug.Print "One file was selected. File (with path) is: "; _
astrFiles(LBound(astrFiles))
Else
i = LBound(astrFiles)
Debug.Print UBound(astrFiles) & _
" files were selected in folder "; _
astrFiles(i)
For i = i + 1 To UBound(astrFiles)
Debug.Print , astrFiles(i)
Next i
End If
End Function
'----- end of code -----