vbaoutlook

How to act upon a "Selection" in Outlook?


Background:

I have a table of variable size/content that is manually inserted to a Outlook email. Borders are manually added to the selection and it is autofit.


Issue:

Outlook does not have a macro recorder, so I cannot find the syntax within Outlook to do the equivalent of Selection.Borders.LineStyle=xlContinuous.


Query:

Does anyone know how to interact with just the selection via VBA for Outlook, possibly providing all borders to said selection?


Tested script:

The below gives RTE 438 on the object, and olContinuous is not a real term (I was able to verify the RTE by making this 1, which does add a line in excel):

    With Application.ActiveExplorer.Selection.Border
        .LineStyle = olContinous
    End With


Edit1: I am trying to see if this is possible to identify the highlighted table/text via WordEditor... havne't gotten very far, but found VBA to format selected text in Outlook which is at least a lead. Will keep trying in the meantime.


Solution

  • I think I figured this out, based on the post referenced in my Edit:

        With ActiveInspector.WordEditor.Windows(1).Selection
            .Borders.OutsideLineStyle = 1
            .Borders.InsideLineStyle = 1
            .Columns.AutoFit
        End With
    

    No other dimensioning is required with this script and executes on my selection. If you do not have a table/columns, .Columns.Autofit throws an error, but beyond that it gets the job done.