Macro to create a table in an Outlook message RRS feed

  • Question

  • I think what I want to do should be pretty simple.

    I want the ability to quickly insert a 1x1 table with some specific formatting (font, background color, etc) into an email message, preferably with a keyboard shortcut, or at least a menu item.

    I'm familiar with VBA programming, but what I'm not familiar with is how to scope this or where to put it so that I can use it for any message I create in Outlook.  My VBA experience is limited to Excel where macros are embedded in the file.

    Can I get some hints?


    Wednesday, January 16, 2013 3:00 PM

All replies

  • OPen Outlook->Alt+F11->Tools->Reference->Select the "Microsoft Word 12.0 Object Library".

    Then from Insert Menu->Standard Module->Paste below code.

    Ensure that one mail inspector before running macro.

    Sub InsertText()
        Const sText As String = "Enter this text at the cursor"
       ' On Error GoTo ErrHandler
        If TypeName(ActiveWindow) = "Inspector" Then
                If ActiveInspector.IsWordMail And ActiveInspector.EditorType = olEditorWord Then
                  With ActiveInspector.WordEditor.Application.activedocument
                    .Tables.Add Range:=.Range, NumRows:=1, NumColumns:= _
                    1, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
                    With .Tables(1)
                        If .Style <> "Table Grid" Then
                         .Style = "Table Grid"
                        End If
                        .ApplyStyleHeadingRows = True
                        .ApplyStyleLastRow = False
                        .ApplyStyleFirstColumn = True
                        .ApplyStyleLastColumn = False
                        .ApplyStyleRowBands = True
                        .ApplyStyleColumnBands = False
                     End With
            End With
                 End If
        End If
        Exit Sub
        MsgBox "Some Error"
    End Sub
    Basically after the 1st With Block I have taken help of Word Macro Recorder.

    Best Regards,
    Asadulla Javed, Kolkata
    Please do not forget to click “Vote as Helpful” if any post helps you and "Mark as Answer”if it solves the issue.

    Thursday, January 17, 2013 12:19 PM