View Single Post
 
Old 08-18-2019, 09:27 AM
gmaxey gmaxey is offline Windows 10 Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

There is a bit here called Learn to Love ranges.


VBA Basics


Actual a table is an object (type table). Declaring a variable just makes coding easier. (I'm not formally trained so could be wrong).

Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oTbl As Object
Dim oTbl2 As Table
Dim lngIndex As Long
  For Each oTbl In ActiveDocument.Tables
    MsgBox TypeName(oTbl)
    oTbl.Range.Cells(1).Range.Text = "AAA"
    MsgBox oTbl.Rows.Count
  Next oTbl
  For Each oTbl2 In ActiveDocument.Tables
    oTbl2.Range.Cells(1).Range.Text = "BBB"
    MsgBox oTbl2.Rows.Count
  Next oTbl2
  For lngIndex = 1 To ActiveDocument.Tables.Count
    ActiveDocument.Tables(lngIndex).Range.Cells(1).Range.Text = "CCC"
    MsgBox ActiveDocument.Tables(lngIndex).Rows.Count
  Next
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/

Last edited by gmaxey; 08-19-2019 at 04:19 AM.
Reply With Quote