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

How to create message Box2 in VBA

Sub Msg_Box()


MsgBox "Testbox", vbYesNo, "karthiken07"

OutPut
End Sub

How to create message Box in VBA

1.Create Command button using form tool bar.

Sub Msg_Box()


MsgBox "Testbox"

End Sub

Output :