|
|
| Next: help find my resume |
| Author |
Message |
Rage External

Since: Aug 11, 2009 Posts: 6
|
Posted: Tue Aug 11, 2009 7:22 am Post subject: Word Macro to Format Tables Archived from groups: microsoft>public>word>tables (more info?) |
|
|
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. |
|
| Back to top |
|
 |
Doug Robbins - Word MVP External

Since: Jul 14, 2006 Posts: 2665
|
Posted: Tue Aug 11, 2009 6:10 pm Post subject: Re: Word Macro to Format Tables [Login to view extended thread Info.] Archived from groups: per prev. post (more info?) |
|
|
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" <Rage DeleteThis @discussions.microsoft.com> wrote in message
news:2D93C485-1C3B-4C76-A3B2-E2C966D74FC8@microsoft.com...
> 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. |
|
| Back to top |
|
 |
Rage External

Since: Aug 11, 2009 Posts: 6
|
Posted: Wed Aug 12, 2009 1:54 am Post subject: Re: Word Macro to Format Tables [Login to view extended thread Info.] Archived from groups: per prev. post (more info?) |
|
|
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" <Rage RemoveThis @discussions.microsoft.com> wrote in message
> news:2D93C485-1C3B-4C76-A3B2-E2C966D74FC8@microsoft.com...
> > 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.
>
> |
|
| Back to top |
|
 |
Doug Robbins - Word MVP External

Since: Jul 14, 2006 Posts: 2665
|
Posted: Thu Aug 13, 2009 12:10 am Post subject: Re: Word Macro to Format Tables [Login to view extended thread Info.] Archived from groups: per prev. post (more info?) |
|
|
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" <Rage.TakeThisOut@discussions.microsoft.com> wrote in message
news:F5E4ACD7-5905-4F79-98B7-A6AA459D3722@microsoft.com...
> 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" <Rage.TakeThisOut@discussions.microsoft.com> wrote in message
>> news:2D93C485-1C3B-4C76-A3B2-E2C966D74FC8@microsoft.com...
>> > 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.
>>
>> |
|
| Back to top |
|
 |
Rage External

Since: Aug 11, 2009 Posts: 6
|
Posted: Thu Aug 13, 2009 1:14 am Post subject: Re: Word Macro to Format Tables [Login to view extended thread Info.] Archived from groups: per prev. post (more info?) |
|
|
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" <Rage.TakeThisOut@discussions.microsoft.com> wrote in message
> news:F5E4ACD7-5905-4F79-98B7-A6AA459D3722@microsoft.com...
> > 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" <Rage.TakeThisOut@discussions.microsoft.com> wrote in message
> >> news:2D93C485-1C3B-4C76-A3B2-E2C966D74FC8@microsoft.com...
> >> > 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.
> >>
> >>
>
> |
|
| Back to top |
|
 |
Doug Robbins - Word MVP External

Since: Jul 14, 2006 Posts: 2665
|
Posted: Thu Aug 13, 2009 5:10 am Post subject: Re: Word Macro to Format Tables [Login to view extended thread Info.] Archived from groups: per prev. post (more info?) |
|
|
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" <Rage.RemoveThis@discussions.microsoft.com> wrote in message
news:2C09CB7E-8870-47F8-A626-6FB6EBB0C141@microsoft.com...
> 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" <Rage.RemoveThis@discussions.microsoft.com> wrote in message
>> news:F5E4ACD7-5905-4F79-98B7-A6AA459D3722@microsoft.com...
>> > 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" <Rage.RemoveThis@discussions.microsoft.com> wrote in message
>> >> news:2D93C485-1C3B-4C76-A3B2-E2C966D74FC8@microsoft.com...
>> >> > 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.
>> >>
>> >>
>>
>> |
|
| Back to top |
|
 |
Rage External

Since: Aug 11, 2009 Posts: 6
|
Posted: Thu Aug 13, 2009 5:10 am Post subject: Re: Word Macro to Format Tables [Login to view extended thread Info.] Archived from groups: per prev. post (more info?) |
|
|
It's no where near 60cm - that's huge - the first and last columns are 1.78
cm long, and the 2nd and 3rd columns are 6.37 cm long, giving a total of 16.3
cm for the table width (which is the same width as my A4 word document not
including margins)...
"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" <Rage.RemoveThis@discussions.microsoft.com> wrote in message
> news:2C09CB7E-8870-47F8-A626-6FB6EBB0C141@microsoft.com...
> > 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" <Rage.RemoveThis@discussions.microsoft.com> wrote in message
> >> news:F5E4ACD7-5905-4F79-98B7-A6AA459D3722@microsoft.com...
> >> > 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" <Rage.RemoveThis@discussions.microsoft.com> wrote in message
> >> >> news:2D93C485-1C3B-4C76-A3B2-E2C966D74FC8@microsoft.com...
> >> >> > 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.
> >> >>
> >> >>
> >>
> >>
>
> |
|
| Back to top |
|
 |
Rage External

Since: Aug 11, 2009 Posts: 6
|
Posted: Thu Aug 13, 2009 5:10 am Post subject: Re: Word Macro to Format Tables [Login to view extended thread Info.] Archived from groups: per prev. post (more info?) |
|
|
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" <Rage.RemoveThis@discussions.microsoft.com> wrote in message
> news:2C09CB7E-8870-47F8-A626-6FB6EBB0C141@microsoft.com...
> > 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" <Rage.RemoveThis@discussions.microsoft.com> wrote in message
> >> news:F5E4ACD7-5905-4F79-98B7-A6AA459D3722@microsoft.com...
> >> > 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" <Rage.RemoveThis@discussions.microsoft.com> wrote in message
> >> >> news:2D93C485-1C3B-4C76-A3B2-E2C966D74FC8@microsoft.com...
> >> >> > 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.
> >> >>
> >> >>
> >>
> >>
>
> |
|
| Back to top |
|
 |
Rage External

Since: Aug 11, 2009 Posts: 6
|
Posted: Thu Aug 13, 2009 5:15 am Post subject: Re: Word Macro to Format Tables [Login to view extended thread Info.] Archived from groups: per prev. post (more info?) |
|
|
In fact - scratch that - I've worked it out.
If anyone cares about this, the working macro is this:
Sub ChangeTableSize()
Dim i As Long
Dim myTable As Table
Dim myrange As Range
For i = 1 To ActiveDocument.Tables.Count
Set myTable = ActiveDocument.Tables(i)
Set myrange = myTable.Range
If (myrange.Information(wdActiveEndPageNumber) > 35) And
(myrange.Information(wdActiveEndPageNumber) < 296) Then
myTable.AutoFitBehavior wdAutoFitFixed
myTable.Columns(1).Width = CentimetersToPoints(1.7
myTable.Columns(2).Width = CentimetersToPoints(6.37)
myTable.Columns(3).Width = CentimetersToPoints(6.37)
myTable.Columns(4).Width = CentimetersToPoints(1.7
End If
Next i
End Sub |
|
| Back to top |
|
 |
Doug Robbins - Word MVP External

Since: Jul 14, 2006 Posts: 2665
|
Posted: Thu Aug 13, 2009 6:10 pm Post subject: Re: Word Macro to Format Tables [Login to view extended thread Info.] Archived from groups: per prev. post (more info?) |
|
|
The following code works fine for me:
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(1.7
.Columns(2).Width = CentimetersToPoints(6.37)
.Columns(3).Width = CentimetersToPoints(6.37)
.Columns(4).Width = CentimetersToPoints(1.7
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" <Rage.RemoveThis@discussions.microsoft.com> wrote in message
news:3B78DA22-302D-443F-89FF-27E3239F5BBC@microsoft.com...
> It's no where near 60cm - that's huge - the first and last columns are
> 1.78
> cm long, and the 2nd and 3rd columns are 6.37 cm long, giving a total of
> 16.3
> cm for the table width (which is the same width as my A4 word document not
> including margins)...
>
> "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" <Rage.RemoveThis@discussions.microsoft.com> wrote in message
>> news:2C09CB7E-8870-47F8-A626-6FB6EBB0C141@microsoft.com...
>> > 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" <Rage.RemoveThis@discussions.microsoft.com> wrote in message
>> >> news:F5E4ACD7-5905-4F79-98B7-A6AA459D3722@microsoft.com...
>> >> > 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" <Rage.RemoveThis@discussions.microsoft.com> wrote in message
>> >> >> news:2D93C485-1C3B-4C76-A3B2-E2C966D74FC8@microsoft.com...
>> >> >> > 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.
>> >> >>
>> >> >>
>> >>
>> >>
>>
>> |
|
| Back to top |
|
 |
Doug Robbins - Word MVP External

Since: Jul 14, 2006 Posts: 2665
|
Posted: Thu Aug 13, 2009 6:10 pm Post subject: Re: Word Macro to Format Tables [Login to view extended thread Info.] Archived from groups: per prev. post (more info?) |
|
|
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.7
.Columns(2).Width = CentimetersToPoints(6.37)
.Columns(3).Width = CentimetersToPoints(6.37)
.Columns(4).Width = CentimetersToPoints(1.7
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" <Rage.TakeThisOut@discussions.microsoft.com> wrote in message
news:477530D8-5D66-49CE-B70D-82622311CD7C@microsoft.com...
>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" <Rage.TakeThisOut@discussions.microsoft.com> wrote in message
>> news:2C09CB7E-8870-47F8-A626-6FB6EBB0C141@microsoft.com...
>> > 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" <Rage.TakeThisOut@discussions.microsoft.com> wrote in message
>> >> news:F5E4ACD7-5905-4F79-98B7-A6AA459D3722@microsoft.com...
>> >> > 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" <Rage.TakeThisOut@discussions.microsoft.com> wrote in message
>> >> >> news:2D93C485-1C3B-4C76-A3B2-E2C966D74FC8@microsoft.com...
>> >> >> > 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.
>> >> >>
>> >> >>
>> >>
>> >>
>>
>> |
|
| Back to top |
|
 |
|
|
|
You can post new topics in this forum You can reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
| |
|
|