MS Word Macros - Text to tables

Discussion in 'Software' started by S Walch, Nov 3, 2011.

  1. S Walch

    S Walch MAME 0.64 :) VIP Member

    Joined:
    Jun 2, 2003
    Messages:
    1,026
    Likes Received:
    14
    Location:
    Manchester
    At the moment I've sorted out a macro to turn a certain selected section of text into a table, the first line containing the text followed by three empty rows, with a maximum of 10 columns.

    How would I sort it so that it takes the first 10 words of a sentence, turns that into a 10 column table with 4 rows, and then creates another tables afterwards with the remaining words in a sentence in a similar sort of table.

    EG, take my first half-sentence in this post. At the moment the macro would turn "At the moment I've sorted out a macro to turn a certain selected section of text into a table" into

    At the moment I've sorted out a macro to turn
    a certain selected section of text into a table
    <empty row>
    <empty row>
    <empty row>

    I'd like to be able to turn it into

    At the moment I've sorted out a macro to turn
    <empty row>
    <empty row>
    <empty row>
    <paragraph space>
    a certain selected section of text into a table
    <empty row>
    <empty row>
    <empty row>

    Anyone able to help with the VB commands for the macro? Or am I trying to be too complicated?
     
    S Walch, Nov 3, 2011
    #1
    1. Advertisements

  2. S Walch

    Ian Administrator

    Joined:
    Mar 27, 2008
    Messages:
    657
    Likes Received:
    7
    That's way about my head unfortunately, however if you post what you've got done in the Macro so far, someone may be able to spot a way to modify it :)
     
    Ian, Nov 5, 2011
    #2
    1. Advertisements

  3. S Walch

    S Walch MAME 0.64 :) VIP Member

    Joined:
    Jun 2, 2003
    Messages:
    1,026
    Likes Received:
    14
    Location:
    Manchester
    Alrighty :)

    Sub TextTables()
    '
    ' TextTables Macro
    '
    '
    Application.DefaultTableSeparator = " "
    WordBasic.TextToTable ConvertFrom:=3, NumColumns:=10, NumRows:=1, _
    InitialColWidth:=wdAutoPosition, Format:=0, Apply:=1184, AutoFit:=1, _
    SetDefault:=0, Word8:=0, Style:="Table Grid"
    With Selection.Tables(1).Rows
    .WrapAroundText = True
    .HorizontalPosition = CentimetersToPoints(2.41)
    .RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
    .DistanceLeft = CentimetersToPoints(0)
    .DistanceRight = CentimetersToPoints(0)
    .VerticalPosition = CentimetersToPoints(0)
    .RelativeVerticalPosition = wdRelativeVerticalPositionParagraph
    .DistanceTop = CentimetersToPoints(0)
    .DistanceBottom = CentimetersToPoints(0)
    .AllowOverlap = False
    End With
    With Selection.ParagraphFormat
    .LeftIndent = CentimetersToPoints(0)
    .RightIndent = CentimetersToPoints(0)
    .SpaceBefore = 0
    .SpaceBeforeAuto = False
    .SpaceAfter = 0
    .SpaceAfterAuto = False
    .LineSpacingRule = wdLineSpaceSingle
    .Alignment = wdAlignParagraphLeft
    .WidowControl = True
    .KeepWithNext = False
    .KeepTogether = False
    .PageBreakBefore = False
    .NoLineNumber = False
    .Hyphenation = True
    .FirstLineIndent = CentimetersToPoints(0)
    .OutlineLevel = wdOutlineLevelBodyText
    .CharacterUnitLeftIndent = 0
    .CharacterUnitRightIndent = 0
    .CharacterUnitFirstLineIndent = 0
    .LineUnitBefore = 0
    .LineUnitAfter = 0
    .MirrorIndents = False
    .TextboxTightWrap = wdTightNone
    .ReadingOrder = wdReadingOrderLtr
    End With
    Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
    Selection.Tables(1).AutoFitBehavior (wdAutoFitContent)
    Selection.InsertRowsBelow 3
    Selection.Font.Size = 9
    End Sub
     
    S Walch, Nov 6, 2011
    #3
  4. S Walch

    S Walch MAME 0.64 :) VIP Member

    Joined:
    Jun 2, 2003
    Messages:
    1,026
    Likes Received:
    14
    Location:
    Manchester
    In which section would I place that? The first or in the "End With" section?
     
    S Walch, Jan 31, 2012
    #4
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.