Reply
 
Thread Tools Display Modes
  #1   Report Post  
Bill Sturdevant
 
Posts: n/a
Default Select specific cells in table via macro

I have a table in Word XP that was created by Pasting Special (HTML) from an
Excel spreadsheet. The first and second rows of the table span the entire
width of the table (merged cells). The remaining rows have cells of varying
widths in many of the rows (not always the same widths down through the
table).

I have created a macro that will do various reformatting (such as shrinking
the width, specifying the border for the table, things that can be done while
in the Table Properties dialog box). Shrinking the width, however, causes
some columns to be sized improperly in some rows depending upon the values in
those cells.

What VB code can I use to select the cells in rows 3 and 4 of column 1 and
then shrink the column width (which simultaneously expands the width of
column 2 of the same rows)?

I have tried to record a macro, but recording a macro does not seem to work
when working directly on a table.

Alternatively, how can I record a macro while working within a table?
  #2   Report Post  
Jezebel
 
Posts: n/a
Default

You appear to be asking two questions. is your objective to select cells or
to set their widths? In VBA code, these are different tasks: you can work
with all parts of a document by manipulating various Range objects; you
don't need to select them to do that. More to the point, perhaps, is that
you are unlikely to be able to record a macro for the purpose. Recording is
a seriously lousy way to create macros: it just doesn't work for anything
much beyond repetitive keystroking.

The key problem in this case is that if the table has merged and split
cells, you won'tr necessarily be able to work with (or select) its column at
all. You can iterate the cells of the table using code like --

Dim pCell as Word.cell

Set pCell = MyTable.cells(1,1)
Do
..... pCell.Width = xxx 'Or whatever you want to do
set pCell = pCell.Next
Loop until pCell is nothing

You can check where the cell is located in the table by looking at its
RowIndex and ColumnIndex properties.




"Bill Sturdevant" wrote in
message ...
I have a table in Word XP that was created by Pasting Special (HTML) from
an
Excel spreadsheet. The first and second rows of the table span the entire
width of the table (merged cells). The remaining rows have cells of
varying
widths in many of the rows (not always the same widths down through the
table).

I have created a macro that will do various reformatting (such as
shrinking
the width, specifying the border for the table, things that can be done
while
in the Table Properties dialog box). Shrinking the width, however, causes
some columns to be sized improperly in some rows depending upon the values
in
those cells.

What VB code can I use to select the cells in rows 3 and 4 of column 1 and
then shrink the column width (which simultaneously expands the width of
column 2 of the same rows)?

I have tried to record a macro, but recording a macro does not seem to
work
when working directly on a table.

Alternatively, how can I record a macro while working within a table?



Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Table in a Form HiDbLevel Tables 12 February 27th 06 12:59 PM
Table AutoFormats vs. Table Styles confusion Tony Jollans Tables 5 March 6th 05 07:18 PM
Select Table dialog box comes up twice when open data source Paula Jern Mailmerge 0 January 6th 05 05:07 PM
How do I select specific information from an imported table smintey Tables 4 December 7th 04 07:54 PM
Word 2003 Table AutoFormat vs Macro vs VBA Kind writer/user/programmer Tables 1 October 28th 04 03:14 PM


All times are GMT +1. The time now is 08:47 AM.

Copyright ©2000 - 2023, Jelsoft Enterprises Ltd.
Copyright 2004-2023 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"