Autofit *all* tables to 'Autofit to Window'

Robie
5StarLounger
Posts: 656
Joined: 18 Feb 2010, 14:26

Autofit *all* tables to 'Autofit to Window'

Post by Robie »

Is there an easy way of doing this rather than going thru each table?

Also, is there a way to reset all Heading styles (Heading1 - Heading4) to 'indent from left' to -1.

Thanks.

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15784
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Autofit *all* tables to 'Autofit to Window'

Post by ChrisGreaves »

Robie wrote:Is there an easy way of doing this rather than going thru each table?
Try the little macro "AutoFitContentAllTables" in the attached document.
You do not have the required permissions to view the files attached to this post.
By definition, educating the client is the consultant’s first objective

User avatar
HansV
Administrator
Posts: 78887
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Autofit *all* tables to 'Autofit to Window'

Post by HansV »

This macro will loop through all tables in the active document:

Code: Select all

Sub AdjustAllTables()
  Dim tbl As Table
  For Each tbl In ActiveDocument.Tables
    tbl.AutoFitBehavior wdAutoFitWindow
  Next tbl
End Sub
Best wishes,
Hans

User avatar
HansV
Administrator
Posts: 78887
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Autofit *all* tables to 'Autofit to Window'

Post by HansV »

And this one will set the left indent for Heading 1...4:

Code: Select all

Sub AdjustStyles()
  ActiveDocument.Styles(wdStyleHeading1).ParagraphFormat.LeftIndent = _
    Application.InchesToPoints(-1)
  ActiveDocument.Styles(wdStyleHeading2).ParagraphFormat.LeftIndent = _
    Application.InchesToPoints(-1)
  ActiveDocument.Styles(wdStyleHeading3).ParagraphFormat.LeftIndent = _
    Application.InchesToPoints(-1)
  ActiveDocument.Styles(wdStyleHeading4).ParagraphFormat.LeftIndent = _
    Application.InchesToPoints(-1)
End Sub
Best wishes,
Hans

Robie
5StarLounger
Posts: 656
Joined: 18 Feb 2010, 14:26

Re: Autofit *all* tables to 'Autofit to Window'

Post by Robie »

Wow. Thanks Chris and Hans. I thought it would reams and reams of VBA code. A big THANKS.

Sorry, one more question in relation to the paragraphs with heading styles. I have found that when I import these document into the current template all the headings are *lowercase*. It seems in their template the heading styles were set with 'ALL CAPS'. Now, is there a way to set up my Heading styles with *Initial letter as CAP*? For example '3. defects fixed in this release' would become '3. Defects fixed in this release'. I can see all options as part of the font settings but not this :sad: .

User avatar
HansV
Administrator
Posts: 78887
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Autofit *all* tables to 'Autofit to Window'

Post by HansV »

"First letter in upper case" is not a font, paragraph or style property. You could run this macro to "repair" the headings:

Code: Select all

Sub FixCaps()
  Dim par As Paragraph
  For Each par In ActiveDocument.Paragraphs
    Select Case par.Style
      Case ActiveDocument.Styles(wdStyleHeading1), _
          ActiveDocument.Styles(wdStyleHeading2), _
          ActiveDocument.Styles(wdStyleHeading3), _
          ActiveDocument.Styles(wdStyleHeading4)
        par.Range.Case = wdTitleSentence
    End Select
  Next par
End Sub
Best wishes,
Hans