Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting a word table cell BLOCK for a range or selection object? 1

Status
Not open for further replies.

ramgni

Technical User
Feb 11, 2002
6
0
0
DE
Hi all,

I may have overlooked something, but somehow I can't get a block of cells extending over several rows and columns grouped into a range or selection object for collective processing (font, frames, alignment...).

If, for instance, I want to set the font for .Cell(2,2) thru .Cell(10,10) in a word table of size 20,20, do I really have to walk through all the cells I want to change the font for individually???

In Excel this is easy, but since tables obviously are not to Word what spreadsheets are to Excel, things seem much more twisted...

TIA,
Ingmar
 
try something like...

Code:
Dim oTable As Word.Table
Dim oRange As Word.Range
Dim nStart As Long
Dim nEnd As Long
Dim oOld As Word.Range

Set oOld = Selection.Range

Set oTable = ActiveDocument.Tables(1)
' get start of first cell
nStart = oTable.Cell(2, 2).Range.Start
' get end of last cell
nEnd = oTable.Cell(4, 4).Range.End
Set oRange = oTable.Range
oRange.SetRange nStart, nEnd
oRange.Select
Selection.Font.Bold = True
Set oRange = Nothing
Set oTable = Nothing

oOld.Select
Set oOld = Nothing
 
Thanks for the tip.

I am getting the error "Object variable or With block variable not set" whenever I try to access the Selection object in this example. I thought that the Selection object was always present in a document. I can't even do a Selection.type in the immediate window after doing the oRange.Select. Why is this? I am using VB 6.0 and I added the reference "Microsoft Word 9.0 Object Library" to my project.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top