Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-27-2023, 03:27 PM
Guessed's Avatar
Guessed Guessed is offline Run a macro from page x to page Y Windows 10 Run a macro from page x to page Y Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,159
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
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Run a macro from page x to page Y inserting a page break after each 9th page? or skip print on the 10th page ? vender Mail Merge 2 05-27-2020 05:18 AM
Custom page size - Page color not covering entire page when converting to PDF icor1031 Word 9 12-09-2019 08:21 PM
Run a macro from page x to page Y Start page number on page 3, go to page not working properly MetroBOS Word 7 01-30-2016 11:31 PM
2 page document printing problem, text from page 1 in layout of page 2 when printed laurawether45 Word 1 08-02-2012 07:03 AM
Run a macro from page x to page Y MS Word, page goes to next page when entering data on previous page munna94 Word 2 12-30-2010 08:12 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:38 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft