title: How get paragraph number of specif text in Word VBA?
body: <p>I need find an specific text in my document and get paragraph number position</p>
  
  <p>This is for Excel VBA</p>
  
  <pre><code>Sub exportardatos()
  'Paso 1: Declare las variables
  Dim Paragraphe As Object, WordApp As Object, WordDoc As Object, WordTable As Object, WordRange As Object
  File = "C:\Users\lper\Documents\FormExp.docx"
  
   On Error Resume Next
  
      'creationsession Word
      Set WordApp = GetObject(class:="Word.Application")
  
      'Clear the error between errors
      Err.Clear
      If WordApp Is Nothing Then Set WordApp = CreateObject(class:="Word.Application")
  
        If Err.Number = 429 Then
          MsgBox "Microsoft Word could not be found, aborting."
          GoTo EndRoutine
        End If
  
    On Error GoTo 0
      WordApp.Visible = True
      WordApp.Activate
      'open the file .doc
      Set WordDoc = WordApp.Documents.Open(File)
  
  
      'Word Enumerated Constants
      Const wdReplaceAll = 2
          WordApp.Documents("FormExp.docx").Activate
          Dim nParag As Long
          Set WordRange = WordApp.ActiveDocument.Paragraphs(1).Range
  
          For Each WordRange In WordDoc.StoryRanges
           With WordApp.Selection.Find
                  .ClearFormatting
                  .Replacement.ClearFormatting
                  .Text = "Legal"
                  .Wrap = wdFindContinue
                  .Execute
                  Do While .Execute = True
                  nParag = WordRange(0, Selection.Paragraphs(1).Range.End).Paragraphs.Count
                  MsgBox (nParag)
                  Loop
  
           End With
          Next WordRange
  
  EndRoutine:
          'Optimize Code
            Application.ScreenUpdating = True
            Application.EnableEvents = True
  
          'Clear The Clipboard
            Application.CutCopyMode = False
  
      'Set WordDoc = Nothing
      'Set WordApp = Nothing
  MsgBox ("Ready")
  End Sub
  </code></pre>
  
  <p>I get code error 438</p>