繁体   English   中英

查找文本并替换文本 excel 字 vba

[英]find text and replace text excel word vba

我有以下代码

  Sub DocSearch()
Dim wdApp As Object, wdDoc As Object
Set wdApp = CreateObject("word.application")
wdApp.Visible = True
Set wdDoc = wdApp.Documents.Open("C:\Documents and Settings\Owner\My Documents\downloads\work\M-F-380.1.doc")
With wdDoc.Content.Find
  .Text = "Date:"
  .Replacement.Text = "Datetest"
  .Wrap = wdFindContinue
  .Execute Replace:=wdReplaceAll
End With
Set wdApp = Nothing: Set wdDoc = Nothing
End Sub

以上工作正常,我在上面的 vba 代码中添加了以下内容,但它不起作用

With wdDoc.Content.Find
  .Text = "Date:"
  .Replacement.Text = "Datetest"
   Text = "Prime Lending Rate"
  .Replacement.Text =" Repo Rate"
  .Wrap = wdFindContinue
  .Execute Replace:=wdReplaceAll

您的帮助将不胜感激

谢谢

你需要有:

.Execute Replace:=wdReplaceAll

在每组 F/R 表达式之间,因此:

Sub DocSearch()
Dim wdApp As Object, wdDoc As Object
Set wdApp = CreateObject("word.application")
wdApp.Visible = True
Set wdDoc = wdApp.Documents.Open("C:\Documents and Settings\Owner\My Documents\downloads\work\M-F-380.1.doc")
With wdDoc.Content.Find
  .Wrap = wdFindContinue
  .Text = "Date:"
  .Replacement.Text = "Datetest"
  .Execute Replace:=wdReplaceAll
  .Text = "Prime Lending Rate"
  .Replacement.Text = " Repo Rate"
  .Execute Replace:=wdReplaceAll
End With
Set wdApp = Nothing: Set wdDoc = Nothing
End Sub

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM