Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / April 2007

Tip: Looking for answers? Try searching our database.

Table resizing

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Fuzzhead - 15 Apr 2007 20:36 GMT
In the past there was not a set way to to create warning, caution or note
boxes in our documents. I have created the following macros to standardize
them. Is the a way to create a macro that will go through a existing document
and resize the table without removing the text that’s in them? All of the old
boxes have the following as the first word:
Note in the Note Box
Caution in the Caution Box
Warning in the Warning Box

Sub NoteBox()
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=1, NumColumns:= _
   1, DefaultTableBehavior:=wdWord9TableBehavior,
AutoFitBehavior:=wdAutoFitFixed
Selection.Tables(1).Rows.SetLeftIndent LeftIndent:=44,
RulerStyle:=wdAdjustNone
Selection.Tables(1).Columns(1).SetWidth ColumnWidth:=423,
RulerStyle:=wdAdjustNone
   If Selection.Font.Underline = wdUnderlineNone Then
       Selection.Font.Underline = wdUnderlineSingle
   Else
       Selection.Font.Underline = wdUnderlineNone
   End If
Selection.TypeText Text:="NOTE"
   If Selection.Font.Underline = wdUnderlineNone Then
       Selection.Font.Underline = wdUnderlineSingle
   Else
       Selection.Font.Underline = wdUnderlineNone
   End If
Selection.TypeText Text:=":"
Selection.TypeText Text:="   "
   With Selection.ParagraphFormat
       .LeftIndent = InchesToPoints(0.63)
       .SpaceBeforeAuto = False
       .SpaceAfterAuto = False
   End With
   With Selection.ParagraphFormat
       .SpaceBeforeAuto = False
       .SpaceAfterAuto = False
       .FirstLineIndent = InchesToPoints(-0.63)
   End With
End Sub

Sub CautionBox()
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=1, NumColumns:= _
   1, DefaultTableBehavior:=wdWord9TableBehavior,
AutoFitBehavior:=wdAutoFitFixed
Selection.Tables(1).Rows.SetLeftIndent LeftIndent:=44,
RulerStyle:=wdAdjustNone
Selection.Tables(1).Columns(1).SetWidth ColumnWidth:=423,
RulerStyle:=wdAdjustNone
Selection.Tables(1).Borders.OutsideLineWidth = wdLineWidth225pt
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.Font.Bold = wdToggle
Selection.Font.Underline = wdUnderlineSingle
Selection.TypeText Text:="CAUTION"
Selection.Font.Underline = wdUnderlineNone
Selection.Font.Bold = wdToggle
Selection.TypeParagraph
Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
End Sub

Sub WarningBox()
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=1, NumColumns:= _
   1, DefaultTableBehavior:=wdWord9TableBehavior,
AutoFitBehavior:=wdAutoFitFixed
Selection.Tables(1).Rows.SetLeftIndent LeftIndent:=44,
RulerStyle:=wdAdjustNone
Selection.Tables(1).Columns(1).SetWidth ColumnWidth:=423,
RulerStyle:=wdAdjustNone
Selection.Tables(1).Borders.OutsideLineWidth = wdLineWidth225pt
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.Font.Bold = wdToggle
Selection.Font.Underline = wdUnderlineSingle
Selection.TypeText Text:="WARNING"
Selection.Font.Underline = wdUnderlineNone
Selection.Font.Bold = wdToggle
Selection.TypeParagraph
Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
End Sub
Lene Fredborg - 15 Apr 2007 22:28 GMT
Based on your macros, I assume that all "boxes" consist of a table with only
one cell.
If this is correct, you may use the macro below to resize the tables. The
macro iterates through all tables in the active document. If the first word
is "NOTE", "CAUTION" or "WARNING" (in any combination of uppercase and
lowercase letters), the macro changes the left indent to 44 and the width to
423 (values taken from your macros) - the contents will not be changed. When
finished, the macro displays a message telling how many tables were resized.

NOTE: If there is any risk that other tables contain one of the words
"Note", "Caution" or "Warning" as the first word, you need to add more code
to check which tables to change.
Also note that you may need to adjust the macro, e.g. depending on the
settings applied to the existing tables.

Sub ResizeTables()
   Dim oTable As Table
   Dim n As Long 'use to count changed tables
   n = 0
   For Each oTable In ActiveDocument.Tables
       With oTable
           Select Case UCase(.Cell(1, 1).Range.Words.First)
               Case "NOTE", "WARNING", "CAUTION"
                   '[insert code that makes the desired changes]
                   '[the following is based on your macros]
                   .Rows.LeftIndent = 44
                   .Columns(1).Width = 423
                   n = n + 1
           End Select
       End With
   Next oTable
   MsgBox "Finished adjusting " & n & " tables."
End Sub

Signature

Regards
Lene Fredborg
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word

> In the past there was not a set way to to create warning, caution or note
> boxes in our documents. I have created the following macros to standardize
[quoted text clipped - 75 lines]
> Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
> End Sub
Fuzzhead - 16 Apr 2007 18:08 GMT
Thank you Lene, it worked great. This is going to save me hours of going
through each document and changing them.

Fuzzhead

> Based on your macros, I assume that all "boxes" consist of a table with only
> one cell.
[quoted text clipped - 109 lines]
> > Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
> > End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.