Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-21-2023, 07:33 AM
azurtem azurtem is offline Executing macro on each subsequent page/table Windows 7 64bit Executing macro on each subsequent page/table Office 2013
Novice
Executing macro on each subsequent page/table
 
Join Date: Apr 2016
Location: nice, france
Posts: 7
azurtem is on a distinguished road
Question Executing macro on each subsequent page/table

Hi



I have the following label template in Windows (v11) Word (v2021) : https://bit.ly/3K8IrKS

The objective is to print a list of mac addresses on individual labels

When merging data into this template, Word naturally fills the cells in from left to right and then from top to bottom

I would like to modify the resulting order of the merged cell entries in the table so as to sort them from top to bottom, and then from left to right

I came across this VBA script, generously shared by Greg Maxey : Table Re-sorter

It produces exactly the sought result; but for one page/table only. Which is totally fine.
Except that I need to execute this sort procedure on the subsequent pages/tables also present in this document

I therefore added some lines of code around the line that calls the "TableSort_Re_Sort" procedure as follows :
Code:
  Dim Pages As Long, PageNb As Long  
  Pages=Selection.Information(wdNumberOfPagesInDocument)
  For PageNb = 1 to Pages
	Selection.GoTo What:=wdGoToPage, Name:=PageNb
	TableSort_Re_Sort
  Next
To test this out, I place the cursor at the top left cell of page/table #1 and then run the macro

The added lines correctly position the cursor on the top left cell of each subsequent page/table through each iteration
But unfortunately, the "TableSort_Re_Sort" procedure only gets executed on page/table #1

If can obtain the desired (global) result (without my added code) if I position the cursor
in the top left cell of each page/table and manually execute the macro

There is obviously something that I don't understand in the VBA mechanism/process and hope that someone can point me in the right direction

Thank you

regards
yann
Reply With Quote
  #2  
Old 07-21-2023, 11:15 PM
gmayor's Avatar
gmayor gmayor is offline Executing macro on each subsequent page/table Windows 10 Executing macro on each subsequent page/table Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Greg's code operates on the selected table. Change it to sequentially process all the tables e.g.
Code:
Sub SortTable()
  'Set the table object = the table with the selection
  On Error GoTo Err_Handler:
  For Each m_Otbl In ActiveDocument.Tables
    'Table must be uniform (not split or merged cells)
    If Not m_Otbl.Uniform Then
        MsgBox "The selected table has split or merge cells and cannot be sorted with this procedure", vbInformation + vbOKOnly, "Non-Uniform Table"
        Exit Sub
    End If
    TableSort_Re_Sort
  Next m_Otbl
  Exit Sub
Err_Handler:
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 07-22-2023, 01:27 AM
azurtem azurtem is offline Executing macro on each subsequent page/table Windows 7 64bit Executing macro on each subsequent page/table Office 2013
Novice
Executing macro on each subsequent page/table
 
Join Date: Apr 2016
Location: nice, france
Posts: 7
azurtem is on a distinguished road
Talking

Spot on ! Thanks Graham
Sorted :]]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Page No 1 changes when subsequent Page No formatted as continuous brigb Word 3 06-28-2023 12:35 PM
Executing macro on each subsequent page/table Menu Macro Not Executing - Need Help Moondoggy Excel 4 01-14-2023 12:49 AM
Executing macro on each subsequent page/table Table Header - have 'continued' on subsequent pages... User12344321 Word Tables 6 07-27-2020 12:45 PM
Executing a Word macro only after a certain date & time rdross51 Word VBA 4 07-07-2017 06:29 AM
Executing macro on each subsequent page/table Shift Excel Cell after executing a macro for second time LearningMacro Excel Programming 2 01-08-2015 03:05 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:13 AM.


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