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 MayorThe 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 DankoI 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.