Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-20-2021, 06:17 AM
shistris03 shistris03 is offline Select between headings excluding section break Windows 10 Select between headings excluding section break Office 2019
Novice
Select between headings excluding section break
 
Join Date: Jun 2021
Posts: 7
shistris03 is on a distinguished road
Default Select between headings excluding section break

Hi guys,

I am using the following code to select between headings for each page at once (not for the whole document). Is there a way to select between headings excluding the section break which I have at the end of each page? The structure of all my pages is as follows:
Page 1:
Heading
Text
Section break

Page 2:
Heading
Text
Section break



Code:
Sub selectbetweenheadings()
'
' selectbetweenheadings Macro
'
'
    Dim p As Paragraph
    Dim i As Long
    Dim reverseFlag As Boolean
    
    reverseFlag = True
    
    'Move the selection forward one paragraph
    'Assumption: The entire first heading paragraph is selected.
    'If not, you'll need to move forward 2.
          If Selection.MoveEnd(wdParagraph, 1) = 1 Then
        Do
            i = Selection.Paragraphs.Count
            Set p = Selection.Paragraphs(i)
            If Left(p.style, 7) = "Heading" Then Exit Do
            'Paragraph is not a heading. try the next one
            If Selection.MoveEnd(wdParagraph, 1) = 0 Then
                'We're at the end of the document
                reverseFlag = False
                Exit Do
            End If
        Loop
    End If
    
    If reverseFlag Then Selection.MoveEnd wdParagraph, -1
End Sub
Thank you.

Last edited by macropod; 06-20-2021 at 04:51 PM. Reason: Added code tags
Reply With Quote
  #2  
Old 06-20-2021, 04:53 PM
macropod's Avatar
macropod macropod is offline Select between headings excluding section break Windows 10 Select between headings excluding section break Office 2016
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

What are you trying to do with the content?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 06-21-2021, 07:22 AM
shistris03 shistris03 is offline Select between headings excluding section break Windows 10 Select between headings excluding section break Office 2019
Novice
Select between headings excluding section break
 
Join Date: Jun 2021
Posts: 7
shistris03 is on a distinguished road
Default

Hello Sir,

I am basically using mail merge via input info from an excel file. I am using the IF function to display the info of the contents that are selected in the excel file (i.e. each content is a different page and is separated via section breaks).

Then I use a macro to export the mail merge to letters. The final form is the attached file.
OPTION 1
You have provided a macro to delete all headings so I am left with the final text to print. What I am trying to achieve (best case scenario) is to have a code to delete the pages that contain only ¶ and section breaks (i.e. pages that do not contain any text).

OPTION 2
Go to each page, select between headings and print the required page.

Option 1 would be ideal but I have seen that it is not easy to achieve. Please advise.

Thank you for your time.
Attached Files
File Type: docx FINALISING AUDIT CHECKLIST DOCUMENT.docx (21.9 KB, 5 views)
Reply With Quote
  #4  
Old 06-21-2021, 02:08 PM
macropod's Avatar
macropod macropod is offline Select between headings excluding section break Windows 10 Select between headings excluding section break Office 2016
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

So, if you're using mailmerge, why are you creating an output that has headings you don't want? Additionally, why aren't you automating the mailmerge to produce the output letters directly (see Send Mailmerge Output to Individual Files in the Mailmerge Tips and Tricks 'Sticky' thread at the top of the mailmerge forum: https://www.msofficeforums.com/mail-...ps-tricks.html)?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 06-22-2021, 01:55 PM
shistris03 shistris03 is offline Select between headings excluding section break Windows 10 Select between headings excluding section break Office 2019
Novice
Select between headings excluding section break
 
Join Date: Jun 2021
Posts: 7
shistris03 is on a distinguished road
Default

I have gone through the very comprehensive guidelines and thank you for that but I am afraid this is not what I am aiming for (or maybe I could not understand that this is my solution).

I have 10 confirmation letters in separate word documents. The same text is repeated numerous times in different parts of these documents. So i combined these documents in a single document added section breaks and headings to easily navigate through and used mail merge to populate the repeated fields.

Each heading is a separate section/confirmation letter, but not all sections are needed at all times. I wish to have a checklist in my data source (i.e. 10 letters) and choose which letters to mail merge. I thought doing this by inserting the whole text in the IF statement stating that if there is a "yes" next to the checklist in the data source then get this text or else bring nothing.

So the end result of the merged document would be to have the 10 letters on a single document but only 3 (for instance) would be the ones selected from the checklist that have text. The remaining 7 would just have a section break and a paragraph mark ¶.

At this stage, I just need the 3 pages, so if i could only delete the pages that do not contain any text.

I hope i could give you an idea of what i am trying to achieve here.
Reply With Quote
  #6  
Old 06-22-2021, 03:32 PM
macropod's Avatar
macropod macropod is offline Select between headings excluding section break Windows 10 Select between headings excluding section break Office 2016
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

None of what you have written detracts from using an automated mailmerge. All that is required is some care in setting up a mailmerge main document containing all letter variants and a means of telling the mailmerge which variant to output - either globally or at the individual client level. This could be done via the mailmerge filters, SKIPIF fields, or flags for each record in the data source.

Technically, there isn't even any need for all the source documents to be combined - they could be linked to a single mailmerge main document via INCLUDETEXT fields.

The same link also includes the topic Split Merged Output to Separate Documents, which is more akin to what you're already trying to do. Either way, you would do better to omit the unwanted headings from the mailmerge main document rather than trying to clear them out afterwards.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 06-23-2021, 12:21 AM
shistris03 shistris03 is offline Select between headings excluding section break Windows 10 Select between headings excluding section break Office 2019
Novice
Select between headings excluding section break
 
Join Date: Jun 2021
Posts: 7
shistris03 is on a distinguished road
Default

Thank you for the info provided.

I shall search word by word what you've described above and hopefully I will find what I need.

Thanks again for your time.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Select between headings excluding section break Next Page Section Break somehow changed to Cont. Section Break; each time fix spreads to prev chap Swarup Word 10 02-15-2021 06:46 PM
Select between headings excluding section break Word 2007, cannot insert Section Break (Continuous), only Section Break (Next Page) btse1 Word 3 11-01-2018 09:23 AM
Section Break (Continuous) counted as Section Break (Next page) wolfer Word VBA 2 01-06-2018 09:51 AM
Select between headings excluding section break Word converts section break to page break before columns, does not insert column breaks eborda Word 1 03-24-2017 11:06 PM
Select between headings excluding section break Section Break (Next Page) replaces Section Break (Continuous) when deleted Carlabasson Word 2 03-25-2013 10:13 PM

Other Forums: Access Forums

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