vba - add page break with macro (if there isnt any page break) -


i want add page break before every heading 1 , evey \page bookmark. code work :

sub pagebreack(isok)     if isok <> true          exit sub     end if     selection.goto = wdgotoline, = wdgotofirst      application.browser.target = wdbrowsepage     = 1 activedocument.builtindocumentproperties("number of pages")         if > 1             activedocument.bookmarks("\page").range.select             selection.insertbreak type:=wdsectionbreakcontinuous  'wdsectionbreaknextpage         end if         application.browser.next     next     each p in activedocument.paragraphs       if left(p.style, 9) = "heading 1"         p.range.select         selection.previous.insertbreak type:=wdsectionbreakcontinuous       end if     next     selection.find.clearformatting     selection.find.replacement.clearformatting     selection.find         .text = "^12": .replacement.text = "^m": .forward = true: .wrap = wdfindcontinue: .format = false: .matchcase = false: .matchwholeword = false: .matchkashida = false: .matchdiacritics = false: .matchalefhamza = false: .matchcontrol = false: .matchwildcards = false: .matchsoundslike = false: .matchallwordforms = false     end     selection.find.execute replace:=wdreplaceall end sub   

my problem code doesnt check exist page break , add new page break there.
how change code macro check if there isnt page break add page break ?
(english not native language , hope explain clearly)

you have blank pages use page break macro here macro delete blank pages in word document

sub demo() activedocument.content.find     .clearformatting     .replacement.clearformatting     .text = "^12[^12^13 ]{1,}"     .replacement.text = "^12"     .forward = true     .wrap = wdfindcontinue     .format = false     .matchwildcards = true     .execute replace:=wdreplaceall end end sub 

reference:remove blank pages docx using word interop

sub pagebreack(isok)     if isok <> true          exit sub     end if     selection.goto = wdgotoline, = wdgotofirst      application.browser.target = wdbrowsepage     = 1 activedocument.builtindocumentproperties("number of pages")         if > 1             activedocument.bookmarks("\page").range.select             selection.insertbreak type:=wdsectionbreakcontinuous  'wdsectionbreaknextpage         end if         application.browser.next     next     activedocument.styles("heading 1").paragraphformat         .pagebreakbefore = true     end     selection.find.clearformatting     selection.find.replacement.clearformatting     selection.find         .text = "^12": .replacement.text = "^m": .forward = true: .wrap = wdfindcontinue: .format = false: .matchcase = false: .matchwholeword = false: .matchkashida = false: .matchdiacritics = false: .matchalefhamza = false: .matchcontrol = false: .matchwildcards = false: .matchsoundslike = false: .matchallwordforms = false     end     selection.find.execute replace:=wdreplaceall     activedocument.content.find         .clearformatting         .replacement.clearformatting         .text = "^12[^12^13 ]{1,}"         .replacement.text = "^12"         .forward = true         .wrap = wdfindcontinue         .format = false         .matchwildcards = true         .execute replace:=wdreplaceall     end end sub 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -