A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Word » Tables
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Word Macro to Format Tables



 
 
Thread Tools Display Modes
  #11  
Old August 13th, 2009, 10:22 PM posted to microsoft.public.word.tables
Doug Robbins - Word MVP
external usenet poster
 
Posts: 8,239
Default Word Macro to Format Tables

Sorry, I should have realised that the Select Case was not working as I was
only using it on a one page document.

Dim i As Long
Dim myTable As Table
Dim myrange As Range
Dim pagenum As Long
With ActiveDocument
For i = 1 To .Tables.Count
Set myTable = .Tables(i)
With myTable
Set myrange = .Range
pagenum = myrange.Information(wdActiveEndPageNumber)
If pagenum 99 And pagenum 201 Then
.AutoFitBehavior wdAutoFitFixed
.Columns(1).Width = CentimetersToPoints(1.78)
.Columns(2).Width = CentimetersToPoints(6.37)
.Columns(3).Width = CentimetersToPoints(6.37)
.Columns(4).Width = CentimetersToPoints(1.78)
End If
End With
Next i
End With

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
"Rage" wrote in message
...
I found out where your macro is going wrong: it's not pointing at the range
of tables, it's just going from table 1, which, in my document, only has 2
columns - do you know of a way to adapt the macro so that it doesn't look
for
the nth table, but looks for the 1st table starting at a specific page,
and
culminating at the last table on another specific page?

"Doug Robbins - Word MVP" wrote:

So you want to make the total width of the table 60cm. That would exceed
the maximum page width that Word can accommodate which is abot 55.88cm.

There is nothing wrong with the macro as long an you do not have it
contain
values that would make the table wider than the maximum page width.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
"Rage" wrote in message
...
4: the four columns are split up into groups of 2, so columns 1 & 4 are
the
same size, and columns 2 & 3 are the same size too.

Cheers

"Doug Robbins - Word MVP" wrote:

How many columns are there in your table?

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
"Rage" wrote in message
...
Hi Doug,

Thanks for your reply! There's only one thing wrong:

I get a:

Run-time error '5941':

The requested member of the collection does not exist.

at the line:
.Columns(3).Width = CentimetersToPoints(6.37)

(I did take out the apostrophe).

Any ideas?

Cheers.





"Doug Robbins - Word MVP" wrote:

Use:

Dim i As Long
Dim myTable As Table
Dim myrange As Range
With ActiveDocument
For i = 1 To .Tables.Count
Set myTable = .Tables(i)
With myTable
Set myrange = .Range
Select Case myrange.Information(wdActiveEndPageNumber)
Case Is 99 201
.AutoFitBehavior wdAutoFitFixed
.Columns(1).Width = CentimetersToPoints(10)
.Columns(2).Width = CentimetersToPoints(2)
'.Columns(3).Width = CentimetersToPoints(#)
'.Columns(4).Width = CentimetersToPoints(#)
End Select
End With
Next i
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of
my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
"Rage" wrote in message
...
Hi gang,

I have a 300-odd MS Word Document (Word Version 2003) with quite
a
lot
of
tables, and I was wondering - can someone possibly provide me
with a
macro
which will take all the tables in a range (e.g.) pages 100 - 200,
and
set
the
width of each column to a specific value (e.g.) column 1 = 10 cm,
column 2
=
20 cm etc.?

All the tables in the range needed have 4 columns, but each
column
needs
to
be a different value to the others.

Thanks in advance,

Rage.







 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


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


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.