Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 06-25-2021, 08:36 PM
gmayor's Avatar
gmayor gmayor is offline How do I on MS Word VBA add and remove rows in the tables using command button macros? Windows 10 How do I on MS Word VBA add and remove rows in the tables using command button macros? Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,144
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

Based on your screenshot


Code:
Private Sub CommandButton1_Click()
Dim oCC As ContentControl
Dim oTable As Table
Dim oRng As Range
    Set oTable = ActiveDocument.Tables(1)
    For Each oCC In oTable.Range.ContentControls
        oCC.LockContentControl = False
    Next oCC
    oTable.Rows.Last.Range.Copy
    Set oRng = oTable.Range
    oRng.Collapse 0
    oRng.Paste
    oRng.ContentControls(1).DropdownListEntries.Item(1).Select
    For Each oCC In oTable.Range.ContentControls
        oCC.LockContentControl = True
    Next oCC
    Set oCC = Nothing
    Set oTable = Nothing
    Set oRng = Nothing
End Sub

Private Sub CommandButton2_Click()
Dim oCC As ContentControl
Dim oTable As Table
    Set oTable = ActiveDocument.Tables(1)
    For Each oCC In oTable.Range.ContentControls
        oCC.LockContentControl = False
    Next oCC
    oTable.Rows.Last.Delete
    For Each oCC In oTable.Range.ContentControls
        oCC.LockContentControl = True
    Next oCC
    Set oCC = Nothing
    Set oTable = Nothing
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
Remove visible command button when attaching in outlook mfiltvedt84 Outlook 11 10-02-2018 04:33 PM
Show table list by using chek box command and save document on sharepoint by using command button Zhibek Word VBA 3 08-16-2018 06:19 PM
How do I on MS Word VBA add and remove rows in the tables using command button macros? Print only specified pages of word by 1 click of command button using vba Zhibek Word VBA 9 08-12-2018 11:44 PM
Word 2013 ActiveX Command Button Failure irallfml@gmail.com Word VBA 1 05-23-2014 04:19 PM
How do I on MS Word VBA add and remove rows in the tables using command button macros? Word VBA: How to create a command button and trigger a function? tinfanide Word VBA 2 12-02-2011 05:51 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:39 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