BobSievert
New Member
- Joined
- Jun 15, 2018
- Messages
- 3
I am working on a Macro to open all .xlsx files in a specific folder and rename a worksheet on each file. Below is the Macro that I am working on, but the Macro isn't finding the folder name Part C D Repeater Section-6.
Any Suggestions
Sub RenameTab_Revised()
Dim ws As Worksheet
strPath = "M:\GIDS\Test"
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) = "xlsx" Then
Set objWorkbook = objExcel.Workbooks.Open(objFile.Path)
On Error Resume Next
Set ws = Sheets("Part C D Repeater Section-6")
On Error GoTo 0
If ws Is Nothing Then
MsgBox "The Worksheet does not exist in " & objWorkbook.Name
objWorkbook.Close True
Else
Sheets("Part C D Repeater Section-6").Select
Sheets("Part C D Repeater Section-6").Name = "Part C D Repeater Section"
objWorkbook.Close True
End If
End If
Next
End Sub
Any Suggestions
Sub RenameTab_Revised()
Dim ws As Worksheet
strPath = "M:\GIDS\Test"
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) = "xlsx" Then
Set objWorkbook = objExcel.Workbooks.Open(objFile.Path)
On Error Resume Next
Set ws = Sheets("Part C D Repeater Section-6")
On Error GoTo 0
If ws Is Nothing Then
MsgBox "The Worksheet does not exist in " & objWorkbook.Name
objWorkbook.Close True
Else
Sheets("Part C D Repeater Section-6").Select
Sheets("Part C D Repeater Section-6").Name = "Part C D Repeater Section"
objWorkbook.Close True
End If
End If
Next
End Sub