|
|
Thread Tools | Display Modes |
#1
|
||||
|
||||
Help with a script, Range to select as of row 1 and column 2 to the end of the table
Hello Pros,
I've been trying all day to figure out how to select from all tables the range as of rows(1) and Column(2), till the end of the table, on all tables. I found a script where I've modified it with my needs How to select a range of the second row to the last row Word VBA - Stack Overflow Where I've coded this script which works well for 1 table: Code:
Dim aTbl As Table Set aTbl = ActiveDocument.Tables(1) Dim NewTable As Boolean 'if not new Table Select All but first row, Else Select whole table If NewTable = 0 Then With aTbl ActiveDocument.Range(.Cell(1, 2).Range.Start, .Rows(.Rows.Count).Range.End).Select End With Else aTbl.Select End If On Error GoTo 0 However, when applied too all table, I've modified it to this script: Code:
Dim xTbl As Table For Each xTbl In ActiveDocument.Tables Dim NewTable As Boolean 'if not new Table Select All but first column, Else Select whole table If NewTable = 0 Then With xTbl ActiveDocument.Range(.Cell(1, 2).Range.Start, .Rows(.Rows.Count).Range.End).Select End With Else xTbl.Select End If Next xTbl On Error GoTo 0 To test potential scripts, I've used 5 columns and 5 rows, x5 tables. Any idea how to fix this issue? I would be sooooooooo greatful for any insights to help me with my script. Cendrinne |
#2
|
||||
|
||||
You cannot select non-contiguous ranges with VBA. You should process each table separately.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
||||
|
||||
Hello Graham, but they will be in a together
It's like, take these below numbers as cells:
1.......2.......3......4.......5 6.......7.......8......9.......10 11.....12.....13.....14.....15 16.....17.....18.....19.....20 So it would be like selecting as of the whole 2nd column to the whole last column. Does that change your perspective? Cendrinne |
#4
|
||||
|
||||
By the way, I don't understand and thing I don't need the script part of....
The part of the script where it mentioned ''New Table'' and Boolean, I don't know why it's there, don't really get it. I've tried to make a script without it, and kept getting error message, on my side anyway.
So if you find a way without it, it's ok too |
#5
|
||||
|
||||
Oh wait, I think I know how this could be possible. Don't know how to write it though. If it's possible to select all table columns, then it's possible to "De-Select", Column 1.
Or Select all Tables, NOT Column 1. Think it's doable? |
#6
|
||||
|
||||
You still have to process each table separately e.g.
Code:
Sub Macro1() Dim oTable As Table Dim i As Integer For Each oTable In ActiveDocument.Tables oTable.Columns(2).Select For i = 3 To oTable.Columns.Count Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend Next i 'do something with the selection here Next oTable 'then move on to the next table End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#7
|
||||
|
||||
Hello Graham,
Quote:
I'll try your latest script and give you news this week. It's very busy time lately for me, so please accept my appologies in advance for any tardy response. Have a great week and Thank you sooooooooo much for guiding me. Much much appreciated Cendrinne |
Tags |
all tables, help please, range.rows |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to script most table column in word document? | Cendrinne | Word VBA | 15 | 03-22-2021 06:45 PM |
Dynamically select a TextBox based on range value | IIOII | Word VBA | 8 | 07-20-2016 11:28 PM |
Help with Index Function to Select Range of Cells | bretyuin | Excel | 1 | 02-24-2016 05:11 AM |
VBA Word Table - Select More than 1 Column at a time - Apply Formatting | jc491 | Word VBA | 12 | 09-24-2015 06:03 AM |
Way to select a range using the mouse on a chart? | omahadivision | Excel Programming | 6 | 12-29-2012 09:21 AM |