Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 12-03-2024, 12:50 PM
genja genja is offline Windows 11 Office 2021
Novice
 
Join Date: Aug 2024
Posts: 3
genja is on a distinguished road
Default Schrödinger's paragraph

Hi everyone,

maybe I am overlooking something very obvious... but, as the topic suggests I have a problem with paragraphs that appear to both exist and not to exist at the same time.


The problem occurs always when when there is an empty paragraph at the end of a content control. I am looking for a way to target this paragraph efficiently and remove it.

My problem is mainly that I cannot find a way to target these paragraphs directly for whatever reason!



I've built a small example to demonstrate my problem:
Lets say I have a content control cc in that one can select three paragraphs (screenshot) of which the last one is empty. The test document looks like this:


It has 6 paragraphs in total of which 2 are placed before the content control, three are or lets say should be within the cc and one is/should be after the cc. The cc is a rich text cc, if that matters.

When I run the code
Code:
Sub countParasInCC()
    Dim doc As Document, cc As ContentControl, ccRange As Range, paraCountCC As Integer, myccTitle As String
    Set doc = ActiveDocument
    myccTitle = "ccTitle"
    Set cc = doc.SelectContentControlsByTitle(myccTitle).Item(1)
    Set ccRange = cc.Range
    paraCountCC = ccRange.Paragraphs.Count
 End Sub
the result is paraCountCC = 2.


However, when i run the code
Code:
Sub countParasDocument()
    Dim doc As Document, paraCountDoc As Integer
    Set doc = ActiveDocument
    paraCountDoc = doc.Range.Paragraphs.Count
End Sub
I get paraCountDoc = 6.



Can somebody explain to me why the empty paragraph is not counted when counting paragraphs in the cc's range but is counted when counting paragraphs in the document range? What is the method to target and remove such paragraphs?


Many thanks in advance!
Reply With Quote
 

Tags
content control, delete empty, paragraphs



Similar Threads
Thread Thread Starter Forum Replies Last Post
Remove extra space before a paragraph and return it to previous paragraph laith93 Word VBA 7 04-27-2022 08:26 AM
a macro to replace paragraph mark with a space applies effect on paragraph marks after the selection drrr Word VBA 2 08-24-2021 03:05 AM
Inserting text from a Userform into a Field in a paragraph in a paragraph in a word document storemaz Word VBA 1 03-13-2020 08:11 AM
Continuous Paragraph across two columns vs Parallel Column Paragraph Pinesh Word 2 03-09-2018 04:24 PM
Cross-reference to paragraph not updating when paragraph moves windhoek2010 Word 1 09-15-2017 08:30 PM

Other Forums: Access Forums

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