【发布时间】:2021-05-06 16:48:14
【问题描述】:
我在这里使用指南:Find and replace in a loop using macro in Excel
我有一个工作簿“TLA Lookup.xlsx”保存在共享位置。它有一个名为 TLAs 的工作表。 A 列由 TLA 列表组成,B 列是相应的企业名称。
我有一个宏来检查 TLA 查找工作簿,只要存在 TLA,就将其替换为公司名称。我可以在同一个工作簿中执行此操作。
我有不同的工作簿,希望在其中进行查找/替换。我每次都必须从 TLA Lookups 工作簿中复制 TLA 表。我想改为自动引用该工作簿。
如何将 TLA 查找引用为宏需要在其中查找/替换文本的工作簿?
Sub find_replace_2()
Dim TLA As String
Dim NAME As String
Dim i As Long
Dim wb As Workbook
Dim sht1 As Worksheet
'Open the Workbook that has all of the TLAs and CI Names from the K drive,
' so now both workbooks are open
Workbooks.Open Filename:= _
"K:\CLE01\Team_QA\Upcoming Change Highlights\TLA Lookup.xlsx"
Set wb = TLA Lookup.xlsx ' <---- Here is where I get a syntax error
Set sht1 = wb.Sheets("TLAs")
For i = 1 To 4000
TLA = wb.sht1.Range("A" & i).Value
NAME = wb.sht1.Range("B" & i).Value
Selection.Replace What:=TLA, replacement:=NAME _
, LookAt:=xlWhole, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat _
:=False, ReplaceFormat:=False
Next i
End Sub
【问题讨论】: