I am new to XCEL VBA and need some help. What I am trying to do may not be possible since I can't find it in manuals or forums, but here goes.
I'm trying to bring up multiple .xls files at the same time and switch back and forth between files to execute code and transfer small bits of data between the files.
I'm getting the "subscript out of range" error with the code below.
Any help would be appreciated.
Thanks
Ron
[VBA]
Public WKBA As Variant
Public WKBB As Variant
Sub GetMultipleWorkbooks()
WKBA = ActiveWorkbook.FullName
Call GetImportFileName(Filename)
WKBB = Filename
Workbooks.Open Filename:=WKBB
Workbooks(WKBA).Activate
' execute code
Workbooks(WKBB).Activate
' execute code
End Sub
[/VBA]
[VBA]
Sub GetImportFileName(Filename)
Dim Filt As String
Dim FilterIndex As Integer
Dim Title As String
' Set up list of filters
Filt = "Text Files (*.txt),*.txt," & _
"Lotus Files (*.prn),*.prn," & _
"Comma Separated Files (*.csv),*.csv," & _
"All Files (*.*),*.*," & _
"Excel Files (*.xls),*.xls"
' Display *.* by default
FilterIndex = 5
' Set the dialog box caption
Title = "Select File to Import"
' Get the file name
Filename = Application.GetOpenFilename _
(FileFilter:=Filt, _
FilterIndex:=FilterIndex, _
Title:=Title)
' Exit if dialog box canceled
If Filename = False Then
MsgBox "No file was selected."
Exit Sub
End If
' Display full path and name of file
MsgBox "You selected : " & Filename
End Sub
[/VBA]
.
.
Edit Lucas: Ron, if you select your code when posting and hit the vba button it will format your code for the forum.