View Single Post
 
Old 03-10-2015, 08:24 AM
gmayor's Avatar
gmayor gmayor is offline Windows 7 64bit Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Hmmm. Going with your suggestion of using autotext, save your document as a macro enabled template, then select the bottom two rows of your second table, press ALT+F3 and save as an autotext entry called ItemAction in the template.

The following macro will then add the autotext entry to the bottom of the table when you tab out of the last cell (the first table should still tab normally) as should tabbing between other cells.

There is some anomaly related to bullets, when you add text to the cells just added, but the basic issue of ease of use for your users is resolved.

Code:
Option Explicit

Sub NextCell()
Dim iWidth As Long
Dim iCol As Long
Dim iRow As Long
Dim oRow As Row
Dim oRng As Range
Dim oCell As Cell
Dim oTable As Table

    If Selection.InRange(ActiveDocument.Tables(2).Range) Then
        Set oTable = ActiveDocument.Tables(2)
        Set oRow = Selection.Rows(1)
        iRow = oRow.Index
        iCol = oRow.Cells.Count
        Set oCell = oTable.Cell(iRow, iCol)
        'If the cursor is not in the last cell of the table, move to the next cell
        On Error GoTo lbl_Exit
        If Not Selection.InRange(oCell.Range) Or _
           Not Selection.InRange(oTable.Rows.Last.Range) Then
            Selection.Cells(1).Next.Select
            Selection.Collapse 1
            GoTo lbl_Exit
        End If
        Set oRng = oTable.Range
        oRng.Collapse 0
        Application.Templates(ThisDocument.FullName). _
                BuildingBlockEntries("ItemAction").Insert _
                Where:=oRng, _
                RichText:=True
        Set oRow = oTable.Rows.Last.Previous
        oRow.Cells(2).Range.ListFormat.RemoveNumbers NumberType:=wdNumberParagraph
        oRow.Cells(3).Range.ListFormat.RemoveNumbers NumberType:=wdNumberParagraph
        'select the first cell of the new row
        oRow.Cells(1).Select
        'move the selection to the start of the cell
        Selection.Collapse 1
        Set oRow = oTable.Rows.Last
        oRow.Cells(1).Range.Paragraphs(1).Range.ListFormat.RemoveNumbers NumberType:=wdNumberParagraph
        oRow.Cells(2).Range.ListFormat.RemoveNumbers NumberType:=wdNumberParagraph
        oRow.Cells(3).Range.ListFormat.RemoveNumbers NumberType:=wdNumberParagraph
    Else
        Set oRow = Selection.Rows(1)
        iRow = oRow.Index
        iCol = oRow.Cells.Count
        Set oCell = Selection.Tables(1).Cell(iRow, iCol)
        If Not Selection.InRange(oCell.Range) Or _
           Not Selection.InRange(Selection.Tables(1).Rows.Last.Range) Then
            Selection.Cells(1).Next.Select
            Selection.Collapse 1
            GoTo lbl_Exit
        Else
            Set oRow = Selection.Tables(1).Rows.Add
            'select the first cell of the new row
            oRow.Cells(1).Select
            'move the selection to the start of the cell
            Selection.Collapse 1
        End If
    End If

lbl_Exit:
    Set oTable = Nothing
    Set oRow = Nothing
    Set oCell = Nothing
    Set oRng = Nothing
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote