Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-15-2020, 02:03 PM
eduzs eduzs is offline Edit a paragraph with a section break Windows 10 Edit a paragraph with a section break Office 2019
Expert
Edit a paragraph with a section break
 
Join Date: May 2017
Posts: 260
eduzs is on a distinguished road
Default Edit a paragraph with a section break

Hi there!
I need a find/replace vba code to do that:
Paragraph before:
any text-Section Break Mark-


Paragraph After:
any text*
*-Section Break Mark-
Where * = paragraph mark
The code should not replace when the paragraph contains only the section break mark.
I will appreciate any help.
Thanks in advance.

Last edited by eduzs; 07-16-2020 at 04:31 AM.
Reply With Quote
  #2  
Old 07-15-2020, 03:01 PM
eduzs eduzs is offline Edit a paragraph with a section break Windows 10 Edit a paragraph with a section break Office 2019
Expert
Edit a paragraph with a section break
 
Join Date: May 2017
Posts: 260
eduzs is on a distinguished road
Default

Thanks all! This workaround works well for my need:

Code:
Dim x as long, oDoc as document, sTmp as string

Set oDoc = activedocument

For x = 1 To oDoc.Paragraphs.Count
    sTmp = oDoc.Paragraphs(x).range.Text
    If InStr(sTmp, Chr(12)) > 0 And Len(sTmp) > 2 Then
        oDoc.Paragraphs(x).range.Select
        With Selection
            .Collapse direction:=wdCollapseEnd
            .MoveLeft unit:=wdCharacter, Count:=1
            .TypeText Chr(13) & Chr(13)
        End With
    End If
Next x
Reply With Quote
  #3  
Old 07-16-2020, 04:51 AM
eduzs eduzs is offline Edit a paragraph with a section break Windows 10 Edit a paragraph with a section break Office 2019
Expert
Edit a paragraph with a section break
 
Join Date: May 2017
Posts: 260
eduzs is on a distinguished road
Default

How do I identify a section break instead of a page break as word identify all as chr(12)?

Breaks types:

wdPageBreak
wdColumnBreak
wdSectionBreakNextPage
wdSectionBreakContinuous
wdSectionBreakEvenPage
wdSectionBreakOddPage
wdLineBreak
wdLineBreakClearLeft
wdLineBreakClearRight
wdTextWrappingBreak

How can I identify if there's a specific break in a selection? (e.g. wdSectionBreakNextPage)
Reply With Quote
  #4  
Old 07-16-2020, 03:54 PM
Guessed's Avatar
Guessed Guessed is offline Edit a paragraph with a section break Windows 10 Edit a paragraph with a section break Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Well for starters, if I wanted to know if there was a section break in my selection and if so, what type it was, I might try something like this.
Code:
Sub WhatIsIt()
  Dim aRng As Range
  If Selection.Sections.Count > 1 Then
    MsgBox "Section Break Type: " & Selection.Sections.Last.PageSetup.SectionStart
  Else
    MsgBox "You don't have a section break there"
  End If
End Sub
When it comes to the other break types, I'm seeing ascii values of 11 and 14 for column and line breaks.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #5  
Old 07-16-2020, 04:22 PM
eduzs eduzs is offline Edit a paragraph with a section break Windows 10 Edit a paragraph with a section break Office 2019
Expert
Edit a paragraph with a section break
 
Join Date: May 2017
Posts: 260
eduzs is on a distinguished road
Default

Thanks! This works to identify the presence of a certain break type.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Edit a paragraph with a 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
Replacing paragraph formatting before column break also changes the next paragraph after the break jjmartin1340 Word 3 09-21-2015 10:50 PM
Edit a paragraph with a section break Section Break (Next Page) replaces Section Break (Continuous) when deleted Carlabasson Word 2 03-25-2013 10:13 PM
URGENT: Mail 'Merge To New Doc' restarts paragraph numbering at each Section break JamesF Mail Merge 0 07-28-2011 07:26 AM

Other Forums: Access Forums

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