View Single Post
 
Old 02-27-2023, 03:27 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
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

Word and Excel's VBA is similar but both rely on fixed units for accuracy. Document:Section:Paragraph/Table are the equivalent of Workbook:Worksheet:Cell

Unfortunately, 'page' is not a fixed unit when you are interested in a specific region of content in Word. You can interrogate the content to find out what page something happens to be sitting on but you will get different results if something unrelated causes a change (eg font size changes).

Sections are something that we can code for easily.
Code:
  Dim aTbl As Table
  For Each aTbl In ActiveDocument.Sections(2).Range.Tables
    'code for table goes here
  Next aTbl
You can see this code is 'fixed' to a static section number. A more flexible solution that might work for you is to have the macro use the current selection to determine which section you wanted to process. Since a selection can span multiple sections your code needs to get specific eg.
Code:
  Dim aTbl As Table, aSect As Section
  Set aSect = Selection.Range.Sections.First
  For Each aTbl In aSect.Range.Tables
    'code for table goes here
    aTbl.Select
  Next aTbl
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote