![]() |
#1
|
||||
|
||||
![]() Hello Pros, I've been searching and trying, can't seem to find a good solution. At times, I've already worked on 20 pages in a big document. There comes a point, you try to find a solution to speed up the tasks. So at times, I do find a given script to help me do the rest the 60 pages. I don't want to start over what I've done on the first 20 pages. I'm not sure if it's colapse I need, and I've even tried: Code:
Set oRng = ActiveDocument.Range(Selection.Range.Start, ActiveDocument.Range.End) Selection.Collapse Direction:=wdCollapseStart Is there a way, to say: "This point forward''? Any insights, please let me know. Cendrinne |
#2
|
||||
|
||||
![]()
You seem to be confusing selections with ranges. If you are processing the tables, then either process the tables in a range or by their index e.g.
To process the last three tables, or the tables after the cursor location . The first example writes a text to the first cell of the last three tables. The second example changes the first cell text in all the tables (where it exists) from the cursor point to the end of the document. Only those tables are processed. There is no need to select a range in order to process it and if you collapse a selection or a range then the selection or range becomes the (empty) point it is collapsed to. Code:
Sub Macro1() Dim oTable As Table Dim lngCount As Long Dim i As Long lngCount = ActiveDocument.Tables.Count For i = lngCount - 2 To lngCount 'process last three tables Set oTable = ActiveDocument.Tables(i) 'do something with oTable e.g. oTable.Cell(1, 1).Range.Text = "This is cell 1" Next i Set oTable = Nothing End Sub Sub Macro2() Dim oRng As Range Dim oTable As Table Set oRng = ActiveDocument.Range(Selection.Range.Start, ActiveDocument.Range.End) For Each oTable In oRng.Tables 'do something with otable e.g. With oTable.Cell(1, 1).Range.Find .Text = "cell 1" .Replacement.Text = "the first cell" .Wrap = wdFindStop .Execute Replace:=wdReplaceAll End With Next oTable Set oTable = Nothing Set oRng = Nothing End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
||||
|
||||
![]()
Remember my previous post, about trying to find a way to affect all the column 1 from all Tables, well I found a solution to what I was aiming for.
I want to format all the tables to have it a certain Font, size, Row height, Row Space Before and After = 1 pt, Vertical alignment to the bottom, all other columns, apart from the column 1, I want to have a right indent of 0.08" = aligned to the RIGHT. On Column 1, want to have a First line indent + start the column at 0.02", All align to the LEFT (reason I've put that part of the script at the end). It does a WONDERFUL JOB, I'm so proud of myself to have figure this out. However, I would need to do that from the start, cause all the work I've done on all the previous tables, where they had other requirements, would be lost. For example, some need more than 1 pt on certain rows. Anyway, here is my Long Script but works ![]() Code:
Application.ScreenUpdating = False Dim xTbl As Table, aCel As Cell, i As Long For Each xTbl In ActiveDocument.Tables With xTbl.Range .Rows.HeightRule = wdRowHeightAuto .Rows.Height = InchesToPoints(0) .Rows.AllowBreakAcrossPages = False End With 'Next xTbl ' Tbl_0SpcB4_Aft_Tbl_only Macro With xTbl.Range .Font.Size = 9 .Font.Name = "Calibri" .ParagraphFormat.Alignment = wdAlignParagraphRight .ParagraphFormat.LineSpacingRule = wdLineSpaceSingle .ParagraphFormat.SpaceBefore = 1 .ParagraphFormat.SpaceBeforeAuto = False .ParagraphFormat.SpaceAfter = 1 .ParagraphFormat.SpaceAfterAuto = False .ParagraphFormat.RightIndent = InchesToPoints(0.08) .Cells.VerticalAlignment = wdCellAlignVerticalBottom End With 'Next xTbl With xTbl.Columns(1) For i = 1 To .Cells.Count .Cells(i).Range.Font.Size = 9 .Cells(i).Range.Font.Name = "Calibri Light" .Cells(i).Range.ParagraphFormat.Alignment = wdAlignParagraphLeft .Cells(i).Range.ParagraphFormat.LeftIndent = InchesToPoints(0.13) .Cells(i).Range.ParagraphFormat.RightIndent = InchesToPoints(0) .Cells(i).Range.ParagraphFormat.FirstLineIndent = InchesToPoints(-0.11) .Cells(i).Range.ParagraphFormat.SpaceBefore = 1 .Cells(i).Range.ParagraphFormat.SpaceAfter = 1 .Cells(i).Range.Cells.VerticalAlignment = wdCellAlignVerticalBottom Next End With With xTbl.Rows(1) For i = 1 To .Cells.Count .Cells(i).Range.Font.Size = 8 Next End With Next xTbl Application.ScreenUpdating = True 'End With On Error GoTo 0 But see, I'm not that bad, just needs more experience to graspe it. OK, got to go to bed, way past my bed time. I'll try to check it up tomorrow morning, or on the weekend. Thank you so much for your patience and efforts. As you can see, I'm also trying my best. Cendrinne ![]() |
#4
|
||||
|
||||
![]()
Your code works OK, but to make it run on a selection of tables set a range as in Macro2 of my last post i.e. the following will format the tables after the cursor position.
Code:
Dim xTbl As Table Dim oRng As Range Dim i As Long Application.ScreenUpdating = False Set oRng = ActiveDocument.Range(Selection.Range.Start, ActiveDocument.Range.End) For Each xTbl In oRng.Tables With xTbl.Range .Rows.HeightRule = wdRowHeightAuto .Rows.Height = InchesToPoints(0) .Rows.AllowBreakAcrossPages = False .Font.Size = 9 .Font.Name = "Calibri" .ParagraphFormat.Alignment = wdAlignParagraphRight .ParagraphFormat.LineSpacingRule = wdLineSpaceSingle .ParagraphFormat.SpaceBefore = 1 .ParagraphFormat.SpaceBeforeAuto = False .ParagraphFormat.SpaceAfter = 1 .ParagraphFormat.SpaceAfterAuto = False .ParagraphFormat.RightIndent = InchesToPoints(0.08) .Cells.VerticalAlignment = wdCellAlignVerticalBottom End With With xTbl.Columns(1) For i = 1 To .Cells.Count .Cells(i).Range.Font.Size = 9 .Cells(i).Range.Font.Name = "Calibri Light" .Cells(i).Range.ParagraphFormat.Alignment = wdAlignParagraphLeft .Cells(i).Range.ParagraphFormat.LeftIndent = InchesToPoints(0.13) .Cells(i).Range.ParagraphFormat.RightIndent = InchesToPoints(0) .Cells(i).Range.ParagraphFormat.FirstLineIndent = InchesToPoints(-0.11) .Cells(i).Range.ParagraphFormat.SpaceBefore = 1 .Cells(i).Range.ParagraphFormat.SpaceAfter = 1 .Cells(i).Range.Cells.VerticalAlignment = wdCellAlignVerticalBottom Next End With With xTbl.Rows(1) For i = 1 To .Cells.Count .Cells(i).Range.Font.Size = 12 Next End With Next xTbl Application.ScreenUpdating = True Set xTbl = Nothing Set oRng = Nothing
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#5
|
||||
|
||||
![]()
Thank you thank you thank you from the bottom of my heart.
I'm learning alot from this forum. Wish I could be, on top of it, a private student. There are so many questions I would have which I can't find in the books I've purchased and web search, or I'm not looking at the right place. Have a wonderful day, Thank you again, and God Bless you ![]() Cendrinne |
![]() |
Tags |
collapse, help please |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Help please, Script to Delete Paragraph marks b4 Tables | Cendrinne | Word VBA | 4 | 02-08-2022 06:54 PM |
Help with a script to find Duplicate data in the same row of a table or tables | Cendrinne | Word VBA | 9 | 09-07-2021 07:54 PM |
Need Help to Script to align all the tables only as of a section to end of doc? | Cendrinne | Word VBA | 4 | 04-05-2021 11:37 AM |
Printing Word-Tables as PDFs without making the borders 1 point | Tobinobi | Word Tables | 3 | 12-12-2017 10:29 AM |
Script starts nesting tables without reason | selman555 | Word VBA | 1 | 10-17-2014 01:01 AM |