Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #17  
Old 05-04-2020, 03:23 PM
macropod's Avatar
macropod macropod is offline Auto Create/Format a Word Document based on Check Boxes Windows 7 64bit Auto Create/Format a Word Document based on Check Boxes Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,521
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

The problem is that your document contains tables other than the ones with checkboxes. The code fails because the expected checkbox isn't found in those tables. Try:
Code:
Sub DeleteCheckedContent()
Application.ScreenUpdating = False
Dim Tbl As Table, r As Long
For Each Tbl In ActiveDocument.Tables
  With Tbl
    If .Cell(1, 1).Range.ContentControls.Count = 1 Then
      If .Cell(1, 1).Range.ContentControls(1).Checked = True Then
        For r = .Rows.Count To 3 Step -1
          .Rows(r).Delete
        Next
        .Cell(2, 2).Range.Text = "Not applicable"
      Else
        For r = .Rows.Count To 2 Step -1
          If .Cell(r, 1).Range.ContentControls(1).Checked = True Then .Rows(r).Delete
        Next
      End If
      .Columns(1).Delete
    End If
  End With
Next
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Auto-populate Text Field When I Click Check Boxes LobaBlanca Word VBA 2 03-14-2019 08:10 PM
Print documents based on boxes checked in word document eshiffman Word VBA 8 04-05-2018 06:26 AM
Need to create document that will auto insert text based on parameters parisfranco Word 13 07-25-2017 03:21 PM
Word document with check boxes JohnW Word 3 12-01-2016 07:43 AM
Table - Check Boxes - Create Select All lajohn1963 Word Tables 2 09-25-2010 11:18 AM

Other Forums: Access Forums

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