|
|
Thread Tools | Display Modes |
#1
|
||||
|
||||
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 Thanks again, Cendrinne Last edited by Cendrinne; 03-27-2021 at 08:41 PM. |
#2
|
||||
|
||||
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 |
#3
|
||||
|
||||
AMAZING, IT WORKED AS IS :) Andrew
Quote:
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 |
#4
|
||||
|
||||
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) 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 |
#5
|
||||
|
||||
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 |
Tags |
align tables in section, help please |
|
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 |
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 |
How to format and align multiple tables in a document in bulk? | Joey Cheung | Word Tables | 1 | 08-08-2014 11:34 PM |
How to right align section numbers in TOC? | Dr Wu | Word | 1 | 01-03-2014 02:07 PM |