C:\Customers\ABC_Company\May2021.xls 销售额 入C:\Customers\ABC_Company\May2021.xls 投诉 icketsC:\Customers\ABC_Company\May2021.xls 机会 rospects[/tr>C:\Suppliers\Northeast\XYZ Inc\Bills.xlsx 1月 1 C:\Suppliers\Northeast\XYZ Inc\Bills.xlsx 2月
我有大约1000个.xls/.xlsx工作簿,每个工作簿都有不同数量的工作表。这些文件位于不同的文件夹中。我确实有一个文件路径/名称和相关工作表名称的列表,我很想知道是否有VBA解决方案可以对列表中指定的文件和工作表执行工作表重命名,该列表看起来像这样:
旧工作表名称例如:
Sub Tester()
Dim rw As Range, wb As Workbook
Set rw = ThisWorkbook.Sheets("Info").Range("A2:C2") 'start here
Do While Application.CountA(rw) = 3 'go until run out of info
If rw.Cells(1).Value <> rw.Cells(1).Offset(-1, 0).Value Then 'different workbook from previous row ?
If Not wb Is Nothing Then wb.Close True 'save changes
Set wb = Workbooks.Open(rw.Cells(1).Value) 'open this workbook
End If
wb.Sheets(rw.Cells(2).Value).Name = rw.Cells(3).Value 'rename sheet
Set rw = rw.Offset(1, 0) 'next row
Loop
If Not wb Is Nothing Then wb.Close True
End Sub