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

Tuesday, May 08, 2012

Updated: Office macro to paste and format TSV text

Outlook (Word) macro to paste TSV text, convert it to a table, then format it using a new style each time.

Sub PasteFormattedTable()
    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
    styles = Array(-162, -208, -250, -222, -236, -176, -194)
    sel.Style = styles(doc.Tables.Count Mod (UBound(styles) + 1))
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...

If some one wishes expert view concerning blogging and
site-building then i recommend him/her to visit this web site, Keep up the nice job.

Take a look at my web page nice article