Saturday, March 24, 2012

User File Browser in VBA

Sub User_FileBrowser()

Dim varFileName As Variant
Dim nLoop As Integer

'For single file selction
'varFileName = Application.GetOpenFilename(, , "Please select source workbook:")

'For Multiple file selection
varFileName = Application.GetOpenFilename(FileFilter:="Excel files (*.xls), *.xls", Title:="Please select source workbook:", MultiSelect:=True)
nLoop = 1


Do

If TypeName(varFileName(nLoop)) = "String" Then
Cells(2, 2).Value = varFileName(nLoop)
Else

MsgBox "Please Select the xls file", vbOKOnly, "Warning!"
Exit Sub

End If

nLoop = nLoop + 1
Loop Until nLoop = UBound(varFileName)

End Sub

No comments:

Post a Comment