Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-12-2017, 07:39 PM
baes10 baes10 is offline Delete rows with content controls Windows 7 64bit Delete rows with content controls Office 2007
Advanced Beginner
Delete rows with content controls
 
Join Date: Dec 2017
Posts: 33
baes10 is on a distinguished road
Default Delete rows with content controls

Hello, could you help me tweek this current vba to include content controls?
It will delete the empty rows but it wont delete with empty content controls. Hope that makes sense. Thank you!
Attached Files
File Type: docm Help.docm (28.9 KB, 3 views)
Reply With Quote
  #2  
Old 12-12-2017, 08:20 PM
macropod's Avatar
macropod macropod is offline Delete rows with content controls Windows 7 64bit Delete rows with content controls Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 20,346
macropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant future
Default

Try:
Code:
Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
Dim Tbl As Table, cel As Cell, r As Long, x As Long
Dim bDel As Boolean, CCtrl As ContentControl
With ActiveDocument
  For Each Tbl In .Tables
    For r = Tbl.Rows.Count To 1 Step -1
      With Tbl.Rows(r)
        If Len(.Range.Text) = .Cells.Count * 2 + 2 Then
          .Delete
        Else
          bDel = True
          For Each cel In .Cells
            If Len(cel.Range.Text) > 2 Then
              If .Range.ContentControls.Count = 0 Then
                bDel = False: Exit For
              Else
                For Each CCtrl In .Range.ContentControls
                  If CCtrl.ShowingPlaceholderText = False Then
                    bDel = False: Exit For
                  End If
                  x = x + Len(CCtrl.Range.Text)
                Next
                If x + 2 <= Len(cel.Range.Text) Then
                  bDel = False: Exit For
                End If
              End If
            End If
          Next cel
          If bDel = True Then Tbl.Rows(r).Delete
        End If
      End With
    Next r
  Next Tbl
End With
Set cel = Nothing: Set Tbl = Nothing
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #3  
Old 12-13-2017, 10:12 AM
baes10 baes10 is offline Delete rows with content controls Windows 7 64bit Delete rows with content controls Office 2007
Advanced Beginner
Delete rows with content controls
 
Join Date: Dec 2017
Posts: 33
baes10 is on a distinguished road
Default

Thank you so much!
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete rows with content controls Delete or merge Content controls with the same name sylvio Word VBA 9 08-30-2017 01:46 AM
Delete rows with content controls Duplicating one or more table rows or an entire table with content controls kevinbradley57 Word VBA 10 08-17-2017 02:13 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
Delete rows with content controls Delete All empty Rows - Print - Undo all Rows deleted Bathroth Word VBA 1 10-01-2014 01:40 PM
Content Controls - Add Table Rows dgiromini Word VBA 1 04-11-2014 03:04 PM

Other Forums: Access Forums - Senior Forums

All times are GMT -7. The time now is 09:58 PM.


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