File does not Open

File does not Open

Anonymous
Not applicable
312 Views
1 Reply
Message 1 of 2

File does not Open

Anonymous
Not applicable
Hi, To Every One
I am selecting the excel file but the file does not open can u tell me where is the mistake.
thanks

Public Sub GetFiles()
Dim Files As Variant
Dim fName As String
Dim excelApp As Excel.Application
Dim wbkobj As Excel.Workbooks
Dim TxtCharacter
Dim Excelobj As Object

On Error Resume Next
Const iTitle = "My Open Dialogue"
Const FilterList = "*.xls,*.xls"
Set Excelobj = GetObject(, "Excel.Application")
Files = Excel.Application.GetOpenFilename(Title:=iTitle, filefilter:=FilterList, filterindex:=1, MultiSelect:=True)
Excelobj.Visible = True
Set wbkobj = excelApp.Workbooks.Open(Files)

End Sub
0 Likes
313 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable
Displays the standard Open dialog box and gets a file name from the user without actually opening any files.

expression.GetOpenFilename(FileFilter, FilterIndex, Title, ButtonText, MultiSelect)

Remarks
This method returns the selected file name or the name entered by the user. The returned name may include a path specification. If MultiSelect is True, the return value is an array of the selected file names (even if only one filename is selected). Returns False if the user cancels the dialog box.

With MultiSelect=True it will return an Array with the selected filenames, even with only one.
Open(Files) will only open 1 file, and only if Files is a string, which is not the case now.
So use
for i=LBound(Files) to UBound(Files)
Open(Files(i))
Next
0 Likes