Excel单词查找和替换

时间:2016-09-22 16:52:31

标签: excel vba excel-vba ms-word

我正在尝试在excel中编写宏来替换word文档中的某些单词。程序在.Application.Selection.Find.Text = "#5"处停止,并弹出错误消息91"对象变量或未设置块变量"。我被困在这条线上。

Sub createword()

   Dim wrdapp As Word.Application
   Dim wrddoc As Word.document
   Dim i As Integer

   Set wrdapp = CreateObject("word.application")
   wrdapp.documents.Open "C:\Users\Administrator\Desktop\Iam.docx"
   wrdapp.Visible = True

   With wrddoc
      **.Application.Selection.Find.Text = "<<<replace1>>>"**
      .Application.Selection.Find.Execute
      .Application.Selection = "word is awesome"
   End With

End Sub

0 个答案:

没有答案