-1
Using the example past in Microsoft MSDN, the following error is displayed:
Run-time error '9': Subscript out of range
VBA code:
Sub Principal()
Dim PathName As String
Dim Filename As String
Dim TabName As String
Dim ControlFile As String
' This macro will import a file into this workbook
Sheets("Sheet1").Select
PathName = Range("O7").Value
Filename = Range("O8").Value
TabName = Range("O9").Value
ControlFile = ActiveWorkbook.Name
Workbooks.Open Filename:=PathName & Filename
ActiveSheet.Name = TabName
Sheets(TabName).Copy After:=Workbooks(ControlFile).Sheets(1)
Windows(Filename).Activate
ActiveWorkbook.Close SaveChanges:=False
Windows(ControlFile).Activate
End Sub
Where are you giving the error? Which line? You have tab 1 of your spreadsheet with the name "Sheet1"?
– Evert