Using the example passed on Microsoft MSDN, the following error appears:
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