1 Reply Latest reply on Jul 5, 2017 6:50 AM by Trevorׅ

    VBA question

    jakec88782761 Level 2

      Hello,

       

      Sorry this isn't specifically related to InDesign. However, I'm trying to write a script in InDesign that can exchange data with Microsoft Word.

      I've only started learning VBA.  So, as part of a test script I'm trying to search the data in the rows of a table.

       

      This is what I've got, but  I'm not sure why it isn't working.

       

      Any advice would be amazing!

       

      Sub test()
      
      
      Dim d As Document
      Dim t As Table
      Dim c1 As Cell
      Dim c2 As Cell
      Dim r As Rows
      
      
      
      
      Set d = ActiveDocument
      
      Set t = d.Tables(1)
      
      Set r = t.Rows
      
      For x = 1 To r.Count
      
      Set c1 = r(x).Cells(1)
      
      c1.Range.Find.MatchWildcards = True
      
      
      c1.Range.Find.Forward = True
      
      
      c1.Range.Find.Text = "Orion3"
          
              Do While True
              
              c1.Range.Find.Execute
              
                  If c1.Range.Find.Found Then
              
                  Debug.Print c1.Range.Text
              
                  Else
              
                  Exit Do
              
              
                   End If
      
              Loop
              
      Next
      
      
      End Sub