Sunday, April 7, 2013

Excel vba 2010 browse select folder and open file

Private Sub CommandButton1_Click()

Dim myfile As Variant
Dim counter As Integer
Dim path As String
myfolder = "c:\tmp\"
ChDir myfolder
myfile = Application.GetOpenFilename(, , , , True)
counter = 1
If IsNumeric(myfile) = True Then
MsgBox "No files selected"
End If
While counter <= UBound(myfile)
path = myfile(counter)
Workbooks.Open path
counter = counter + 1
Wend

End Sub

No comments: