A pedant that hangs out in the dark corner-cases of the web.

Monday, May 07, 2012

Office macro to paste and format TSV text

Outlook (Word) macro to paste TSV text, convert it to a table, then format it.
Sub PasteBlackTable()
    Dim doc As Word.Document
    Dim sel As Word.Selection
    Dim start As Integer
    Set doc = Application.ActiveInspector.WordEditor
    Set sel = doc.Windows(1).Selection
    start = sel.start
    sel.PasteSpecial Link:=False, DataType:=wdPasteText
    sel.start = start
    sel.ConvertToTable DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:=wdAutoFitContent
    sel.Style = wdStyleTableMediumShading1 ' medium shading 1 (black) = -162
    'sel.Style = wdStyleTableMediumShading1Accent1 ' medium shading 1 accent 1 (blue) = -176
    'sel.Style = -194 ' medium shading 1 accent 3 (red)
    'sel.Style = -208 ' medium shading 1 accent 3 (green)
    'sel.Style = -222 ' medium shading 1 accent 4 (purple)
    'sel.Style = -236 ' medium shading 1 accent 5 (teal)
    'sel.Style = -250 ' medium shading 1 accent 6 (orange)
End Sub
See Getting Started with VBA in Outlook 2010 to get started.
For more style codes, see Create list of built-in style names.

1 comment:

Anonymous said...

I've been surfing on-line more than 3 hours nowadays, but I never found any interesting article like yours. It is pretty value sufficient for me. Personally, if all site owners and bloggers made excellent content material as you did, the web shall be a lot more helpful than ever before.

my blog :: I recommend you read this