0

Input:

##TABLE_START##
##ROWS=3
##COLS=2
##Value
##Decode
##0
##Clock running
##1
##Clock not running
##TABLE_END##

##TABLE_START##
##ROWS=4
##COLS=2
##Value
##Decode
##0
##Off
##1
##On
##Z
##High Z
##TABLE_END##

Desired output:

Data into tables

I want to do this for about 400 tables. I tried recording a macro in word, but it locks the mouse when recording the macro, and it just records the absolute keys hit. I would like to do something more general that searches for ##TABLE_START##, parses all the rows until ##TABLE_END##, then builds a table at the bottom of the document filled in with the appropriate information.

Current Code Word VBA 2010: (Just a snippet of the code -- It just recorded the keystrokes whereas I want to make something that works for every table)

The copy and paste is good, but I need to change how the selection is made to be more general and work for every table

Selection.MoveDown Unit:=wdLine, Count:=7
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.PasteAndFormat (wdFormatOriginalFormatting)
Selection.MoveUp Unit:=wdLine, Count:=6
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Copy
Selection.MoveDown Unit:=wdLine, Count:=7
Selection.PasteAndFormat (wdFormatOriginalFormatting)

1 Answer 1

1

Note: I'm aware this isn't a complete answer

This should get you started by searching line by line for the word "start". When found, you can start building the table. Then you can see StackOverflow creating tables.

Sub tablemaker()
Dim dDoc As Document
Set dDoc = ActiveDocument
Dim rRng As Range
Dim p As Paragraph
   
For Each p In dDoc.Paragraphs
Set rRng = p.Range
    With rRng.Find
       .Text = "start"
        If .Execute Then
        'create table
        Set rRng = Nothing
        End If
    End With
    Next
End Sub

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .