Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-27-2021, 06:33 PM
Cendrinne's Avatar
Cendrinne Cendrinne is offline Need Help to Script to align all the tables only as of a section to end of doc? Windows 10 Need Help to Script to align all the tables only as of a section to end of doc? Office 2019
Competent Performer
Need Help to Script to align all the tables only as of a section to end of doc?
 
Join Date: Aug 2019
Location: Montreal Quebec Canada
Posts: 190
Cendrinne is on a distinguished road
Default Need Help to Script to align all the tables only as of a section to end of doc?

Hello Word VBA pros,



I'm trying to script to have all tables, as of the active Section, (so this point forward), to have all tables with a LeftIndent of 0.38 InchesToPoints.

This is what I've came up with, but it doesn't work.

Need help to fix it up, Please

HTML Code:
 Application.ScreenUpdating = False
    Dim aTbl As Table
    Dim oSec As Section
    Dim oRng As range
    
    For Each aTbl In ActiveDocument.Tables
      Set oRng = oSec.range

       aTbl.Rows.Alignment = wdAlignRowLeft
       aTbl.Rows.LeftIndent = InchesToPoints(0.38)
       aTbl.Rows.WrapAroundText = False
  Next aTbl
  
Application.ScreenUpdating = True
  On Error GoTo 0
Any help, would be greatly appreciated.

Thanks again,

Cendrinne

Last edited by Cendrinne; 03-27-2021 at 08:41 PM.
Reply With Quote
  #2  
Old 03-27-2021, 11:28 PM
Guessed's Avatar
Guessed Guessed is offline Need Help to Script to align all the tables only as of a section to end of doc? Windows 10 Need Help to Script to align all the tables only as of a section to end of doc? Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
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

This point forward or this section forward are two different things. Both options are in this code.
Code:
Sub Tabulator()
  Dim aTbl As Table, oRng As Range
  Application.ScreenUpdating = False
    
    'Set oRng = ActiveDocument.Range(Selection.Range.Start, ActiveDocument.Range.End)
    Set oRng = ActiveDocument.Range(Selection.Range.Sections(1).Range.Start, ActiveDocument.Range.End)
    For Each aTbl In oRng.Tables
       aTbl.Rows.Alignment = wdAlignRowLeft
       aTbl.Rows.LeftIndent = InchesToPoints(0.38)
       aTbl.Rows.WrapAroundText = False
    Next aTbl
  
  Application.ScreenUpdating = True
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 03-27-2021, 11:59 PM
Cendrinne's Avatar
Cendrinne Cendrinne is offline Need Help to Script to align all the tables only as of a section to end of doc? Windows 10 Need Help to Script to align all the tables only as of a section to end of doc? Office 2019
Competent Performer
Need Help to Script to align all the tables only as of a section to end of doc?
 
Join Date: Aug 2019
Location: Montreal Quebec Canada
Posts: 190
Cendrinne is on a distinguished road
Red face AMAZING, IT WORKED AS IS :) Andrew

Quote:
Originally Posted by Guessed View Post
This point forward or this section forward are two different things. Both options are in this code.
Code:
    Set oRng = ActiveDocument.Range(Selection.Range.Sections(1).Range.Start,
Amazing as is. Smart!!!!

Since the section I wanted to apply your macro was in Section 9, I've modified your (1) for (9), it said '''The collection number doesn't existe''.

I was like ''What???''.

So since, I know, you know your stuff, I've tried your macro AS IS, and as usual, you were right!!!!

I bow to the Master Pro!!!!

My question to you is Why I had to use the 1 instead of the 9?

And THANK YOU SOOOOO MUCH.

Cendrinne
Reply With Quote
  #4  
Old 03-28-2021, 02:36 PM
Guessed's Avatar
Guessed Guessed is offline Need Help to Script to align all the tables only as of a section to end of doc? Windows 10 Need Help to Script to align all the tables only as of a section to end of doc? Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
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

Cendrinne

Think about VBA commands as basically a roadmap, zooming in to lower levels as you go. It is similar to saying Earth.Canada.Quebec.Montreal - each steps gives greater resolution. We can't just say Montreal because there are Montreal streets in cities all over the world.

Each vba command is part of a chain that provides context for the next command. Sections(1) tells you something but without the context preceding it we can only guess which Section was intended.

ActiveDocument.Sections(2).Paragraph(3) would be saying -> think of the active document, now in that document think of the second section, now in that section think of the third paragraph

Selection.Range.Sections(1).Range.Start is saying -> go to the current selection, then convert it into a range object, then look at the entire section where that range starts, then convert that section into a range, then tell me the position where that range starts. So all of that is just to work out a position which I then use to define the start of a range.

Code:
ActiveDocument.Range(Selection.Range.Sections(1).Range.Start, ActiveDocument.Range.End)
is saying
Go to the active document and then in that document think of a range that starts with the a position (as described in above paragraph) and ends at the end of the document.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #5  
Old 04-05-2021, 11:37 AM
Cendrinne's Avatar
Cendrinne Cendrinne is offline Need Help to Script to align all the tables only as of a section to end of doc? Windows 10 Need Help to Script to align all the tables only as of a section to end of doc? Office 2019
Competent Performer
Need Help to Script to align all the tables only as of a section to end of doc?
 
Join Date: Aug 2019
Location: Montreal Quebec Canada
Posts: 190
Cendrinne is on a distinguished road
Default I had to rearead it twice, but I think I get it :)

Wow, I think I'm getting what you are saying, Andrew.

Thank you, you succeeded to explain it in a way I would comprehend this stuff.

I thank you beyond words can express 😊

Cendrinne
Reply With Quote
Reply

Tags
align tables in section, help please

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Something in header with text boxes won't let a section align vertically - sometimes ryannah05 Word 5 04-10-2020 09:48 AM
Need Help to Script to align all the tables only as of a section to end of doc? vba script to align text to the center olybobo Excel Programming 1 05-26-2016 01:09 AM
Script starts nesting tables without reason selman555 Word VBA 1 10-17-2014 01:01 AM
Need Help to Script to align all the tables only as of a section to end of doc? How to format and align multiple tables in a document in bulk? Joey Cheung Word Tables 1 08-08-2014 11:34 PM
Need Help to Script to align all the tables only as of a section to end of doc? How to right align section numbers in TOC? Dr Wu Word 1 01-03-2014 02:07 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:18 PM.


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