View Single Post
 
Old 09-11-2016, 06:13 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2013
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Graham's Macro3 code would be faster than the earlier alternatives of stepping through every paragraph.

I would suggest using InStr instead of .Start to get a bit more flexibility in where the found string might appear.
Code:
Sub Macro4()
  Dim oRng As Range
  Dim sText As String, sFind As String
  
  sFind = "010" & Chr$(9)
  Set oRng = ActiveDocument.Range
  With oRng.Find
    Do While .Execute(FindText:=sFind)
      sText = oRng.Paragraphs(1).Range.Text
      If InStr(sText, sFind) = 1 Then
        MsgBox sText
      End If
      oRng.Collapse 0
    Loop
  End With
lbl_Exit:
  Set oRng = Nothing
  Exit Sub
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote