Table resizing

F

Fuzzhead

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
 
L

Lene Fredborg

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

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

Fuzzhead

Thank you Lene, it worked great. This is going to save me hours of going
through each document and changing them.

Fuzzhead



Lene Fredborg said:
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

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


Fuzzhead said:
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
 

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

Similar Threads

Find and Replace Question 3
Multiple Tables 2
Table Format help 1
Line thickness 1
Word 2007 Not responding 0
Table Repeating Issue 1
If Then Else question 3
Populating a Table 8

Top