Word VBA

css navigation by Css3Menu.com

Insert Formatted Text

I get unusual requests! I built a Word Template for my friend to construct his philatelic exhibit. The problem was that he already has hundreds of pages built, each one is a separate document.

The revised idea is to have a pop-up dialog that allows his to insert his text in each page.

Word dialog

The dialog box has examples of the 2 colors that the text should be.

Completed Text

Private Sub cmdCancel_Click()
    Unload usrFormatHeadings		 Empty the form    
    usrFormatHeadings.Hide		 Hide the form
End Sub

Private Sub cmdDoIt_Click()

    On Error GoTo cmdDoIt_Click_Error

    usrFormatHeadings.Hide		 'Hide the form but retain use of fields    
If optLevel1 = True Then
        RunInsertTop
    Else
        RunInsertLower
    End If
   On Error GoTo 0
   Exit Sub

cmdDoIt_Click_Error:

    MsgBox "Error " & Err.Number & " (" & Err.Description _
        & ") in procedure cmdDoIt_Click of Form usrFormatHeadings"
End Sub


Sub OpenBox() usrFormatHeadings.Show 'Show the dialog Unload usrFormatHeadings End Sub Sub RunInsertTop() Selection.Font.Size = 16 'Set all formatting parameters before laying down text Selection.Font.ColorIndex = wdDarkBlue Selection.Font.Bold = True Selection.ParagraphFormat.TabStops.Add Position:=InchesToPoints(7.0), _ Alignment:=wdAlignTabRight, Leader:=wdTabLeaderSpaces Selection.TypeText Text:=usrFormatHeadings.txtTopLeft & vbTab Left side and Tab Selection.EndKey Selection.Font.Size = 14 Selection.Font.Bold = True Selection.Font.ColorIndex = wdDarkBlue Selection.TypeText Text:=usrFormatHeadings.txtTopRight Right side Selection.Font.Bold = False Selection.Font.ColorIndex = wdBlack Selection.Font.Size = 11 Selection.InsertParagraph Next line is ‘normal’ Selection.MoveDown End Sub Sub RunInsertLower() usrFormatHeadings.Hide Selection.Font.Size = 16 Selection.Font.ColorIndex = wdBlue Sub-Chapter is different shade of Blue Selection.Font.Bold = True Selection.ParagraphFormat.TabStops.Add Position:=InchesToPoints(7.0), _ Alignment:=wdAlignTabRight, Leader:=wdTabLeaderSpaces Selection.TypeText Text:=usrFormatHeadings.txtSubLeft & vbTab Selection.EndKey Selection.Font.Size = 14 Selection.Font.Bold = True Selection.Font.ColorIndex = wdBlue Selection.TypeText Text:=usrFormatHeadings.txtSubRight Selection.Font.Bold = False Selection.Font.ColorIndex = wdBlack Selection.Font.Size = 11 Selection.InsertParagraph Selection.MoveDown End Sub

There were several issues:
  1. I had not programmed anything in Word in years
  2. My friend’s computer was corrupted and would not hold the settings
  3. The syntax was so much different form Excel and Access (thanks to the guys at Windows Secrets for putting up with my questions)
  4. My friend kept changing his mind about what he really wanted and what color it should be.

© 2015-2016

Updated:  11/16/2016 19:50
This page added:  15 January 2015