I am really new to VBA. I am trying to use the code below to rename one worksheet in multiple files within one folder, but I keep getting a Subscript Out of Range error at the underlined line. The names are accurate, so that isn't the issue. Can anyone tell me what else could be wrong?
Sub RenameTab_Revised()
strPath = "C:\Documents and Settings\Desktop\Testing VB Code\"
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.DisplayAlerts = False
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFso.GetFolder(strPath)
For Each objFile In objFolder.Files
If objFso.GetExtensionName(objFile.Path) = "xls" Then
Set objWorkbook = objExcel.Workbooks.Open(objFile.Path)
Sheets("Local EMC Support").Select
Sheets("Local EMC Support").Name = "TIF Debt"
objWorkbook.Close True
End If
Next
End Sub
Thanks!
Sub RenameTab_Revised()
strPath = "C:\Documents and Settings\Desktop\Testing VB Code\"
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.DisplayAlerts = False
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFso.GetFolder(strPath)
For Each objFile In objFolder.Files
If objFso.GetExtensionName(objFile.Path) = "xls" Then
Set objWorkbook = objExcel.Workbooks.Open(objFile.Path)
Sheets("Local EMC Support").Select
Sheets("Local EMC Support").Name = "TIF Debt"
objWorkbook.Close True
End If
Next
End Sub
Thanks!