Forum Discussion

a_bonsey's avatar
a_bonsey
Brass Contributor
May 16, 2022

vba table valid row count

Hi,

I'm supplied Word documents that contain a table that has differing valid rows therefore I need a variable to count the valid rows.
In Excel this would be something like:

Sub Test()
    With ActiveSheet
    lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
    MsgBox lastRow
    End With
End Sub

 I can use the following within word vba to count rows excluding the header row but I don't appear to be able to get .End(xlUP)

Dim row As Integer

Dim excelApp As Object

Set excelApp = CreateObject("Excel.Application")

row = excelApp.Worksheetfunction.Clean(ActiveDocument.Tables(1).UsedRange.Rows.Count

 

Any ideas how I can count valid rows?

 

TIA

 

  • a_bonsey 

    Use 

    Dim objSS As InlineShape
    With ActiveDocument.InlineShapes(1)
        .OLEFormat.DoVerb wdOLEVerbHide
        With .OLEFormat.Object.Application
            With .workbooks(1).Worksheets(1)
                MsgBox .Range("A1").currentregion.Rows.Count
            End With
        End With
    End With
    • a_bonsey's avatar
      a_bonsey
      Brass Contributor
      Thanks for that response.
      I tried running and go the error message 'the requested member of the collection does not exist'
      The table is there and editable so any ideas why it errors?

      TIA

Resources