Reputation: 826
From the following code TCN.docx
file had opened successfully using
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
?
Upvotes: 0
Views: 2231
Reputation: 25663
To use Range.Find instead of Selection.Find:
Dim rng As Word.Range
Set rng = odoc.Content
rng
for Selection
in the rest of your code (except for the last line that does the pasting)Note that you may be able to remove the line for activating the Window where you want to paste the information.
Upvotes: 2