Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-22-2018, 07:25 PM
baes10 baes10 is offline Reset content controls in specific row. Windows 7 64bit Reset content controls in specific row. Office 2007
Advanced Beginner
Reset content controls in specific row.
 
Join Date: Dec 2017
Posts: 33
baes10 is on a distinguished road
Default Reset content controls in specific row.

Hello, could you please help me create a VBA to reset the form fields in a specific row?
The adding and deleting vba works just fine.
My nurses are running into a road block when trying to delete a row with filled content.
Currently they have to delete the content or reset the content if you will in each column before deleting the row. I'd like to be able to place the cursor in the row in any column and click a button to reset the form fields in that row only.


Can you help?
Thanks a million.
Steve
Attached Files
File Type: docm Test.docm (145.4 KB, 12 views)
Reply With Quote
  #2  
Old 02-22-2018, 08:33 PM
macropod's Avatar
macropod macropod is offline Reset content controls in specific row. Windows 7 64bit Reset content controls in specific row. Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Try:
Code:
Sub DeleteOneRow()
Application.ScreenUpdating = False
Dim lProt As Long, CCtrl As ContentControl: Const StrPwd As String = ""
'Ensure we're within the row 3 or higher in the 2nd table
With Selection
  If .Information(wdWithInTable) = False Then Exit Sub
  If ActiveDocument.Range(0, .Range.End).Tables.Count <> 2 Then Exit Sub
  If .Cells(1).RowIndex < 3 Then Exit Sub
End With
'Delete the selected row
With ActiveDocument
  lProt = .ProtectionType
  If lProt <> wdNoProtection Then .Unprotect Password:=StrPwd
  With .Tables(2).Rows(Selection.Cells(1).RowIndex)
    For Each CCtrl In .Range.ContentControls
      CCtrl.LockContentControl = False
    Next
    .Delete
  End With
  If lProt <> wdNoProtection Then .Protect Type:=lProt, Password:=StrPwd 
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 02-23-2018, 12:45 PM
baes10 baes10 is offline Reset content controls in specific row. Windows 7 64bit Reset content controls in specific row. Office 2007
Advanced Beginner
Reset content controls in specific row.
 
Join Date: Dec 2017
Posts: 33
baes10 is on a distinguished road
Default

Thank you so much! works like a charm!
Reply With Quote
  #4  
Old 02-23-2018, 06:23 PM
baes10 baes10 is offline Reset content controls in specific row. Windows 7 64bit Reset content controls in specific row. Office 2007
Advanced Beginner
Reset content controls in specific row.
 
Join Date: Dec 2017
Posts: 33
baes10 is on a distinguished road
Default

Hi macropod, sorry for coming back to this, I'm now able to delete specific rows by pressing ALT-W, however it will not allow me to delete the first row. Could you help?
Thanks!
Attached Files
File Type: docm Skin Report Template.docm (164.1 KB, 9 views)
Reply With Quote
  #5  
Old 02-23-2018, 10:00 PM
macropod's Avatar
macropod macropod is offline Reset content controls in specific row. Windows 7 64bit Reset content controls in specific row. Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

As the comments in the code indicate, it won't delete the first two rows of your table. To change that, simply edit the line:
If .Cells(1).RowIndex < 3 Then Exit Sub
and adjust the comments to suit. Do note that it was coded the way for consistency with your DeleteAllRowsNew macro. If you delete all rows, including the 2nd row, you'll lose the ability to add new rows with the necessary content.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #6  
Old 02-26-2018, 10:14 AM
baes10 baes10 is offline Reset content controls in specific row. Windows 7 64bit Reset content controls in specific row. Office 2007
Advanced Beginner
Reset content controls in specific row.
 
Join Date: Dec 2017
Posts: 33
baes10 is on a distinguished road
Default

Thank you again and noted. Works perfectly!
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Reset content controls in specific row. Listbox Content Control - Reset default/prompt? ArtKilp Word VBA 7 08-08-2017 05:31 PM
Reset content controls in specific row. Problems Copy table content and reset contentControls h0mebrewer Word VBA 1 12-14-2016 05:37 PM
Macro to save docx to doc that checks compatibility and converts content controls to static content. staicumihai Word VBA 4 10-12-2016 08:23 PM
VBA for content controls ciresuark Word VBA 1 03-10-2015 03:14 PM
Reset content controls in specific row. Content Controls Sammie0Sue Word 6 11-06-2013 10:56 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:04 AM.


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