Autofit

M

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?
 
D

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
 
G

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
 
G

Graham Mayor

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top