VBA是否要基于文件/工作表列表重命名多个目录中的多个工作表



我有大约1000个.xls/.xlsx工作簿,每个工作簿都有不同数量的工作表。这些文件位于不同的文件夹中。我确实有一个文件路径/名称和相关工作表名称的列表,我很想知道是否有VBA解决方案可以对列表中指定的文件和工作表执行工作表重命名,该列表看起来像这样:

旧工作表名称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.xlsx1月1C:\Suppliers\Northeast\XYZ Inc\Bills.xlsx2月

例如:

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

最新更新