我正在尝试创建一个宏,它将根据另一个工作簿中的数组重命名工作簿中的所有工作表。例如,它将取名为“Alaska”,在引用的表中找到它,并返回几行之外的值,从而导致选项卡重命名为“AK”。但是,我收到两个错误,一个是运行时错误1004,“应用程序定义或对象定义错误”。我可以通过约束for循环来暂时关闭这个,但是它不会随着for循环工作而消失。主要问题是它与vlookup有错误,“无法获取工作表函数类的vlookup属性”。如果有人能查看我的代码并告诉我出了什么问题,那就太棒了。
Dim key As Workbook
Dim ws_count As Integer
Dim search_range As Range
Dim InputString As String
Dim i As Integer
Dim x As String
Set key = Workbooks.Open("\\path")
With key.Sheets(1)
Set search_range = .Range("D3:H" & .Range("H3").End(xlDown).Row)
End With
Set wb = ThisWorkbook
ws_count = ThisWorkbook.Worksheets.Count
'defines ws_count as number of worksheets
InputString = key.Sheets("Sheet1").Cells(i, 7) '<-----Error!
For Each ws In ThisWorkbook
ws.Name = Application.WorksheetFunction.VLookup(InputString, search_range, 4, False) '<----- Error!
Next ws
'continues to repeat process until all sheet names formatted
End Sub