[英]How to open a word document and find text in it without showing the document?
From the following code TCN.docx
file had opened successfully using 从以下代码中,
TCN.docx
文件已成功使用打开
Application.ScreenUpdating = False
instead of 代替
Visible:= False
Sub workonTCN()
Dim odoc As Document
Dim path As String
path = "C:\Users\Bilal\Desktop\TCN.docx"
Set odoc = Documents.Open(filename:=path)
Application.ScreenUpdating = False
Selection.Find.ClearFormatting
Selection.Find.Font.Bold = True
With Selection.Find
.Text = "TI"
.Forward = True
.Wrap = wdFindStop
.Format = True
End With
Selection.Find.Execute
If Selection.Find.Found = True Then
Selection.MoveRight Unit:=wdCell
Selection.COPY
Else
End If
Windows("ROUGH").Activate
odoc.Close wdDoNotSaveChanges
Selection.PasteAndFormat (wdPasteDefault)
End sub
How do I apply range to find text without Selection.Find
? 我如何应用范围来查找没有
Selection.Find
文本?
To use Range.Find instead of Selection.Find: 要使用Range.Find而不是Selection.Find:
Dim rng As Word.Range
Dim rng As Word.Range
Set rng = odoc.Content
Set rng = odoc.Content
rng
for Selection
in the rest of your code (except for the last line that does the pasting) rng
代替Selection
(最后一行粘贴时除外) Note that you may be able to remove the line for activating the Window where you want to paste the information. 请注意,您可以删除用于激活要粘贴信息的窗口的行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.