Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #4  
Old 03-10-2015, 08:24 AM
gmayor's Avatar
gmayor gmayor is offline Adding table row to text style Windows 7 64bit Adding table row to text style Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,142
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 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
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding table row to text style how to apply table style WITHOUT setting it as a table? dylansmith Excel 9 05-16-2014 07:25 PM
Can't change color of text in table style ABode Word 6 12-03-2013 07:45 AM
How to change style of text in table? SCMiller Word VBA 1 04-24-2012 08:31 AM
Matching text style to drawing object style notarichman PowerPoint 0 03-07-2011 11:34 AM
Adding a paragraph mark by style? Jazz43 Word 0 02-14-2011 06:08 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:51 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft