Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #3  
Old 06-28-2021, 12:01 PM
ananas1171 ananas1171 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 2016
Novice
How do I on MS Word VBA add and remove rows in the tables using command button macros?
 
Join Date: Jun 2021
Posts: 5
ananas1171 is on a distinguished road
Default

Quote:
Originally Posted by gmayor View Post
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


Thanks for the response, this worked like a charm. I am experiencing issues when I try to restrict the form and to only allow fill out information in certain fields. When I lock the form and click add or remove row I receive the following;


Run time error '4605', This command is not available.

Based on the your previous posting on other links, I saw that you had a code regarding restrictions of form editing. I am guessing there has to be a code for password. I am trying to figure out how to apply this. Would be able to help me again?
Attached Images
File Type: png Remove column.PNG (33.3 KB, 17 views)
File Type: png Add Column.PNG (45.8 KB, 17 views)
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 02:28 PM.


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