Discussion:
Autofit
(too old to reply)
Maya
2010-04-26 08:48:01 UTC
Permalink
In Word 2007 i want to use Auto fit to fit more than one table in the
document, I dont want to go one by one for each table and click autofit. Is
there a way to do autofit in 1 click for all tables in a document?
Doug Robbins - Word MVP
2010-04-26 10:50:49 UTC
Permalink
Run a macro containing the following code

Dim i As Long
With ActiveDocument
For i = 1 To .Tables.Count
.Tables(i).AutoFitBehavior = True
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
Post by Maya
In Word 2007 i want to use Auto fit to fit more than one table in the
document, I dont want to go one by one for each table and click autofit. Is
there a way to do autofit in 1 click for all tables in a document?
Jordan Danko
2010-08-13 13:38:26 UTC
Permalink
I get an error that the requested member of the collection does not exist. I have a specific table that I am trying to autofit in a document with multiple tables. This table I am pasting into word using a macro. I am able to select the entire table but upon selection it, I cannot figure out how to autofit the table without getting an error message. Please help.
Post by Maya
In Word 2007 i want to use Auto fit to fit more than one table in the
document, I dont want to go one by one for each table and click autofit. Is
there a way to do autofit in 1 click for all tables in a document?
Post by Doug Robbins - Word MVP
Run a macro containing the following code
Dim i As Long
With ActiveDocument
For i = 1 To .Tables.Count
.Tables(i).AutoFitBehavior = True
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
Submitted via EggHeadCafe - Software Developer Portal of Choice
Changing WCF Service Implementation at Runtime
http://www.eggheadcafe.com/tutorials/aspnet/d9263dcc-f7ed-42f3-bc96-321461be3306/changing-wcf-service-implementation-at-runtime.aspx
Graham Mayor
2010-08-13 13:59:56 UTC
Permalink
The following will paste the table from the clipboard at the cursor (though
you can set oRng to be anywhere you wish) and set the autofit parameter to
the pasted table

Dim oTable As Table
Dim oRng As Range
Set oRng = Selection.Range
oRng.Paste
Set oTable = oRng.Tables(1)
oTable.AutoFitBehavior wdAutoFitContent

There are two other possible values for autofit behaviour
wdAutofitWindow
and
wdAutoFitFixed
Post by Jordan Danko
I get an error that the requested member of the collection does not exist.
I have a specific table that I am trying to autofit in a document with
multiple tables. This table I am pasting into word using a macro. I am able
to select the entire table but upon selection it, I cannot figure out how
to autofit the table without getting an error message. Please help.
Graham Mayor
2010-08-13 14:04:19 UTC
Permalink
The error message suggests that you don't have a table selected when you
attempt to format it.
You will get the same error with the posted code if there is no table copied
to the clipboard when you run it.
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Post by Graham Mayor
The following will paste the table from the clipboard at the cursor
(though you can set oRng to be anywhere you wish) and set the autofit
parameter to the pasted table
Dim oTable As Table
Dim oRng As Range
Set oRng = Selection.Range
oRng.Paste
Set oTable = oRng.Tables(1)
oTable.AutoFitBehavior wdAutoFitContent
There are two other possible values for autofit behaviour
wdAutofitWindow
and
wdAutoFitFixed
Post by Jordan Danko
I get an error that the requested member of the collection does not exist.
I have a specific table that I am trying to autofit in a document with
multiple tables. This table I am pasting into word using a macro. I am
able to select the entire table but upon selection it, I cannot figure out
how to autofit the table without getting an error message. Please help.
Loading...