|
本帖最后由 yian123 于 2020-4-26 21:34 编辑
百度了很久,因为平时我都是在excel写代码。在word中调试了很久,好像不能随心所欲操作excel,只能读取之类的。下面代码实现了效果,有的地方是多余的,
Sub AA()
Dim projectno As String
Dim myxls As Object, wb As Object, i As Integer, p As String
Set myxls = CreateObject("excel.application") '启动Excel程序
myxls.Visible = True '不可见'C:\Users\Administrator\Desktop\批量查找并显示\常见错.xlsx 这是文件地址,然后我把词汇文件改为了 常见错.xlsx。
Set wb = myxls.Workbooks.Open("C:\Users\Administrator\Desktop\批量查找并显示\常见错.xlsx")
Set sht = wb.worksheets(1)
i = 1
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Font.Color = 12611584
Do
i = i + 1
p = wb.ActiveSheet.Cells(i, 1)
If p = "" Then Exit Sub
With Selection.Find
.Text = p
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Loop
wb.Save
wb.Close
myxls.Quit
Set myxls = Nothing
End Sub
|
|