Word 2010 - page break before H2 except after H1
I've got a word document with more or less the following structure:
Title
Heading 1
Heading 2
Text
Heading 2
Text
Heading 1
Heading 2
Text
...
I'd like page breaks before all H2 headings, except the ones directly after H1 headings, when I'd prefer the two headings to be on the same page.
I know I can automatically set "page break before" in the style for Heading 2, but is there some way I can set an "except directly after Heading 1" option without having to add all the page breaks manually?
In other words, I'd like the breaks as follows:
Title
-- Page Break --
Heading 1
Heading 2
Text
-- Page Break --
Heading 2
Text
-- Page Break --
Heading 1
Heading 2
Text
-- Page Break --
Heading 2
Text
...
microsoft-word microsoft-word-2010
add a comment |
I've got a word document with more or less the following structure:
Title
Heading 1
Heading 2
Text
Heading 2
Text
Heading 1
Heading 2
Text
...
I'd like page breaks before all H2 headings, except the ones directly after H1 headings, when I'd prefer the two headings to be on the same page.
I know I can automatically set "page break before" in the style for Heading 2, but is there some way I can set an "except directly after Heading 1" option without having to add all the page breaks manually?
In other words, I'd like the breaks as follows:
Title
-- Page Break --
Heading 1
Heading 2
Text
-- Page Break --
Heading 2
Text
-- Page Break --
Heading 1
Heading 2
Text
-- Page Break --
Heading 2
Text
...
microsoft-word microsoft-word-2010
add a comment |
I've got a word document with more or less the following structure:
Title
Heading 1
Heading 2
Text
Heading 2
Text
Heading 1
Heading 2
Text
...
I'd like page breaks before all H2 headings, except the ones directly after H1 headings, when I'd prefer the two headings to be on the same page.
I know I can automatically set "page break before" in the style for Heading 2, but is there some way I can set an "except directly after Heading 1" option without having to add all the page breaks manually?
In other words, I'd like the breaks as follows:
Title
-- Page Break --
Heading 1
Heading 2
Text
-- Page Break --
Heading 2
Text
-- Page Break --
Heading 1
Heading 2
Text
-- Page Break --
Heading 2
Text
...
microsoft-word microsoft-word-2010
I've got a word document with more or less the following structure:
Title
Heading 1
Heading 2
Text
Heading 2
Text
Heading 1
Heading 2
Text
...
I'd like page breaks before all H2 headings, except the ones directly after H1 headings, when I'd prefer the two headings to be on the same page.
I know I can automatically set "page break before" in the style for Heading 2, but is there some way I can set an "except directly after Heading 1" option without having to add all the page breaks manually?
In other words, I'd like the breaks as follows:
Title
-- Page Break --
Heading 1
Heading 2
Text
-- Page Break --
Heading 2
Text
-- Page Break --
Heading 1
Heading 2
Text
-- Page Break --
Heading 2
Text
...
microsoft-word microsoft-word-2010
microsoft-word microsoft-word-2010
asked Dec 26 '12 at 10:26
BristolBristol
1931111
1931111
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Creating a new style will accomplish what you want. Try this procedure:
- Use the Paragraphs dialog box to make
Word
insert a page break before all Heading 2 text. - Create a new style, "Heading 2 Prime", that's exactly like Heading 2, but uncheck the "page break before" option. Be sure you spell "Heading 2 Prime" exactly as written here.
- Press Alt+F11 to open the
VBA development environment
, then click "Insert > Module" to open a new window for entering programs. - Paste the following statements into the window. These statements replace all Heading 2 paragraphs that come after Heading 1 paragraphs, with the Heading 2 Prime style.
Code to paste:
'''''''''''''''''''''''''''''''''''''''''''
Sub replace_Heading2_with_Heading2Prime()
Dim i As Integer
Dim s As String
Dim h As String
'''''''''''''''''''''''''''''''''''''
'loop through all pgp and report heading 2
For i = 1 To ActiveDocument.Paragraphs.Count
s = ActiveDocument.Paragraphs(i).Style
If (s = "Heading 2") Then
h = findPriorHeading(i - 1)
If (h = "Heading 1") Then
ActiveDocument.Paragraphs(i).Style = "Heading 2 Prime"
End If
End If
Next i
Exit Sub
End Sub
Function findPriorHeading(iPgp As Integer) As Variant
Dim i As Integer
Dim blnFoundHeading As Boolean
'walk backwards until any heading is found
With ActiveDocument
i = iPgp
blnFoundHeading = False
Do Until (i < 1 Or blnFoundHeading)
s = .Paragraphs(i).Style
If (InStr(s, "Heading") > 0) Then
blnFoundHeading = True
findPriorHeading = s
Exit Function
End If
i = i - 1
Loop
End With
findPriorHeading = ""
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Press Alt+F11 to return to Word
, then press Alt+F8 to open the Macros dialog box. Double click the "replace_Heading2_with_Heading2Prime" item to run the macro.
I hope this helps.
Can you try cleaning up your example code? I would but I can't figure out where things should be broken up. Try using the editor buttons at the top of the text box to make code blocks out of the sample code.
– slm
Dec 30 '12 at 14:28
Sorry about the ugly code. I've cleaned up the formatting. All of the content with the grey background, which is all of the bold text, is code. Select all of that, and just that, and paste it into the VBA editor as the instructions indicate.
– Darrin Koltow
Dec 30 '12 at 15:14
While not exactly what I was hoping for, this works (and suggests that there is no simple checkbox solution for this) so +1.
– Bristol
Jan 28 '13 at 15:25
add a comment |
My solution is:
- Tick the box for "Page break before" in the style properties for H2,
- For each instance of H1, go to its associated "x.1", i.e. the first instance of H1, open paragraph properties and manually untick the box for "Page break before".
Just like Darrin Koltow solution in this thread, this has its pros (no need for a separate style) and cons (still requires some manual work), and it is clearly a matter of preference.
I really cannot see why this is not a built-in feature though. I've managed to find this and this to prove uservoice is the official channel for requests, but don't have time atm to look into this further.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f524319%2fword-2010-page-break-before-h2-except-after-h1%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Creating a new style will accomplish what you want. Try this procedure:
- Use the Paragraphs dialog box to make
Word
insert a page break before all Heading 2 text. - Create a new style, "Heading 2 Prime", that's exactly like Heading 2, but uncheck the "page break before" option. Be sure you spell "Heading 2 Prime" exactly as written here.
- Press Alt+F11 to open the
VBA development environment
, then click "Insert > Module" to open a new window for entering programs. - Paste the following statements into the window. These statements replace all Heading 2 paragraphs that come after Heading 1 paragraphs, with the Heading 2 Prime style.
Code to paste:
'''''''''''''''''''''''''''''''''''''''''''
Sub replace_Heading2_with_Heading2Prime()
Dim i As Integer
Dim s As String
Dim h As String
'''''''''''''''''''''''''''''''''''''
'loop through all pgp and report heading 2
For i = 1 To ActiveDocument.Paragraphs.Count
s = ActiveDocument.Paragraphs(i).Style
If (s = "Heading 2") Then
h = findPriorHeading(i - 1)
If (h = "Heading 1") Then
ActiveDocument.Paragraphs(i).Style = "Heading 2 Prime"
End If
End If
Next i
Exit Sub
End Sub
Function findPriorHeading(iPgp As Integer) As Variant
Dim i As Integer
Dim blnFoundHeading As Boolean
'walk backwards until any heading is found
With ActiveDocument
i = iPgp
blnFoundHeading = False
Do Until (i < 1 Or blnFoundHeading)
s = .Paragraphs(i).Style
If (InStr(s, "Heading") > 0) Then
blnFoundHeading = True
findPriorHeading = s
Exit Function
End If
i = i - 1
Loop
End With
findPriorHeading = ""
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Press Alt+F11 to return to Word
, then press Alt+F8 to open the Macros dialog box. Double click the "replace_Heading2_with_Heading2Prime" item to run the macro.
I hope this helps.
Can you try cleaning up your example code? I would but I can't figure out where things should be broken up. Try using the editor buttons at the top of the text box to make code blocks out of the sample code.
– slm
Dec 30 '12 at 14:28
Sorry about the ugly code. I've cleaned up the formatting. All of the content with the grey background, which is all of the bold text, is code. Select all of that, and just that, and paste it into the VBA editor as the instructions indicate.
– Darrin Koltow
Dec 30 '12 at 15:14
While not exactly what I was hoping for, this works (and suggests that there is no simple checkbox solution for this) so +1.
– Bristol
Jan 28 '13 at 15:25
add a comment |
Creating a new style will accomplish what you want. Try this procedure:
- Use the Paragraphs dialog box to make
Word
insert a page break before all Heading 2 text. - Create a new style, "Heading 2 Prime", that's exactly like Heading 2, but uncheck the "page break before" option. Be sure you spell "Heading 2 Prime" exactly as written here.
- Press Alt+F11 to open the
VBA development environment
, then click "Insert > Module" to open a new window for entering programs. - Paste the following statements into the window. These statements replace all Heading 2 paragraphs that come after Heading 1 paragraphs, with the Heading 2 Prime style.
Code to paste:
'''''''''''''''''''''''''''''''''''''''''''
Sub replace_Heading2_with_Heading2Prime()
Dim i As Integer
Dim s As String
Dim h As String
'''''''''''''''''''''''''''''''''''''
'loop through all pgp and report heading 2
For i = 1 To ActiveDocument.Paragraphs.Count
s = ActiveDocument.Paragraphs(i).Style
If (s = "Heading 2") Then
h = findPriorHeading(i - 1)
If (h = "Heading 1") Then
ActiveDocument.Paragraphs(i).Style = "Heading 2 Prime"
End If
End If
Next i
Exit Sub
End Sub
Function findPriorHeading(iPgp As Integer) As Variant
Dim i As Integer
Dim blnFoundHeading As Boolean
'walk backwards until any heading is found
With ActiveDocument
i = iPgp
blnFoundHeading = False
Do Until (i < 1 Or blnFoundHeading)
s = .Paragraphs(i).Style
If (InStr(s, "Heading") > 0) Then
blnFoundHeading = True
findPriorHeading = s
Exit Function
End If
i = i - 1
Loop
End With
findPriorHeading = ""
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Press Alt+F11 to return to Word
, then press Alt+F8 to open the Macros dialog box. Double click the "replace_Heading2_with_Heading2Prime" item to run the macro.
I hope this helps.
Can you try cleaning up your example code? I would but I can't figure out where things should be broken up. Try using the editor buttons at the top of the text box to make code blocks out of the sample code.
– slm
Dec 30 '12 at 14:28
Sorry about the ugly code. I've cleaned up the formatting. All of the content with the grey background, which is all of the bold text, is code. Select all of that, and just that, and paste it into the VBA editor as the instructions indicate.
– Darrin Koltow
Dec 30 '12 at 15:14
While not exactly what I was hoping for, this works (and suggests that there is no simple checkbox solution for this) so +1.
– Bristol
Jan 28 '13 at 15:25
add a comment |
Creating a new style will accomplish what you want. Try this procedure:
- Use the Paragraphs dialog box to make
Word
insert a page break before all Heading 2 text. - Create a new style, "Heading 2 Prime", that's exactly like Heading 2, but uncheck the "page break before" option. Be sure you spell "Heading 2 Prime" exactly as written here.
- Press Alt+F11 to open the
VBA development environment
, then click "Insert > Module" to open a new window for entering programs. - Paste the following statements into the window. These statements replace all Heading 2 paragraphs that come after Heading 1 paragraphs, with the Heading 2 Prime style.
Code to paste:
'''''''''''''''''''''''''''''''''''''''''''
Sub replace_Heading2_with_Heading2Prime()
Dim i As Integer
Dim s As String
Dim h As String
'''''''''''''''''''''''''''''''''''''
'loop through all pgp and report heading 2
For i = 1 To ActiveDocument.Paragraphs.Count
s = ActiveDocument.Paragraphs(i).Style
If (s = "Heading 2") Then
h = findPriorHeading(i - 1)
If (h = "Heading 1") Then
ActiveDocument.Paragraphs(i).Style = "Heading 2 Prime"
End If
End If
Next i
Exit Sub
End Sub
Function findPriorHeading(iPgp As Integer) As Variant
Dim i As Integer
Dim blnFoundHeading As Boolean
'walk backwards until any heading is found
With ActiveDocument
i = iPgp
blnFoundHeading = False
Do Until (i < 1 Or blnFoundHeading)
s = .Paragraphs(i).Style
If (InStr(s, "Heading") > 0) Then
blnFoundHeading = True
findPriorHeading = s
Exit Function
End If
i = i - 1
Loop
End With
findPriorHeading = ""
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Press Alt+F11 to return to Word
, then press Alt+F8 to open the Macros dialog box. Double click the "replace_Heading2_with_Heading2Prime" item to run the macro.
I hope this helps.
Creating a new style will accomplish what you want. Try this procedure:
- Use the Paragraphs dialog box to make
Word
insert a page break before all Heading 2 text. - Create a new style, "Heading 2 Prime", that's exactly like Heading 2, but uncheck the "page break before" option. Be sure you spell "Heading 2 Prime" exactly as written here.
- Press Alt+F11 to open the
VBA development environment
, then click "Insert > Module" to open a new window for entering programs. - Paste the following statements into the window. These statements replace all Heading 2 paragraphs that come after Heading 1 paragraphs, with the Heading 2 Prime style.
Code to paste:
'''''''''''''''''''''''''''''''''''''''''''
Sub replace_Heading2_with_Heading2Prime()
Dim i As Integer
Dim s As String
Dim h As String
'''''''''''''''''''''''''''''''''''''
'loop through all pgp and report heading 2
For i = 1 To ActiveDocument.Paragraphs.Count
s = ActiveDocument.Paragraphs(i).Style
If (s = "Heading 2") Then
h = findPriorHeading(i - 1)
If (h = "Heading 1") Then
ActiveDocument.Paragraphs(i).Style = "Heading 2 Prime"
End If
End If
Next i
Exit Sub
End Sub
Function findPriorHeading(iPgp As Integer) As Variant
Dim i As Integer
Dim blnFoundHeading As Boolean
'walk backwards until any heading is found
With ActiveDocument
i = iPgp
blnFoundHeading = False
Do Until (i < 1 Or blnFoundHeading)
s = .Paragraphs(i).Style
If (InStr(s, "Heading") > 0) Then
blnFoundHeading = True
findPriorHeading = s
Exit Function
End If
i = i - 1
Loop
End With
findPriorHeading = ""
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Press Alt+F11 to return to Word
, then press Alt+F8 to open the Macros dialog box. Double click the "replace_Heading2_with_Heading2Prime" item to run the macro.
I hope this helps.
edited Dec 31 '12 at 7:45
slm
6,44563847
6,44563847
answered Dec 30 '12 at 14:06
Darrin KoltowDarrin Koltow
663
663
Can you try cleaning up your example code? I would but I can't figure out where things should be broken up. Try using the editor buttons at the top of the text box to make code blocks out of the sample code.
– slm
Dec 30 '12 at 14:28
Sorry about the ugly code. I've cleaned up the formatting. All of the content with the grey background, which is all of the bold text, is code. Select all of that, and just that, and paste it into the VBA editor as the instructions indicate.
– Darrin Koltow
Dec 30 '12 at 15:14
While not exactly what I was hoping for, this works (and suggests that there is no simple checkbox solution for this) so +1.
– Bristol
Jan 28 '13 at 15:25
add a comment |
Can you try cleaning up your example code? I would but I can't figure out where things should be broken up. Try using the editor buttons at the top of the text box to make code blocks out of the sample code.
– slm
Dec 30 '12 at 14:28
Sorry about the ugly code. I've cleaned up the formatting. All of the content with the grey background, which is all of the bold text, is code. Select all of that, and just that, and paste it into the VBA editor as the instructions indicate.
– Darrin Koltow
Dec 30 '12 at 15:14
While not exactly what I was hoping for, this works (and suggests that there is no simple checkbox solution for this) so +1.
– Bristol
Jan 28 '13 at 15:25
Can you try cleaning up your example code? I would but I can't figure out where things should be broken up. Try using the editor buttons at the top of the text box to make code blocks out of the sample code.
– slm
Dec 30 '12 at 14:28
Can you try cleaning up your example code? I would but I can't figure out where things should be broken up. Try using the editor buttons at the top of the text box to make code blocks out of the sample code.
– slm
Dec 30 '12 at 14:28
Sorry about the ugly code. I've cleaned up the formatting. All of the content with the grey background, which is all of the bold text, is code. Select all of that, and just that, and paste it into the VBA editor as the instructions indicate.
– Darrin Koltow
Dec 30 '12 at 15:14
Sorry about the ugly code. I've cleaned up the formatting. All of the content with the grey background, which is all of the bold text, is code. Select all of that, and just that, and paste it into the VBA editor as the instructions indicate.
– Darrin Koltow
Dec 30 '12 at 15:14
While not exactly what I was hoping for, this works (and suggests that there is no simple checkbox solution for this) so +1.
– Bristol
Jan 28 '13 at 15:25
While not exactly what I was hoping for, this works (and suggests that there is no simple checkbox solution for this) so +1.
– Bristol
Jan 28 '13 at 15:25
add a comment |
My solution is:
- Tick the box for "Page break before" in the style properties for H2,
- For each instance of H1, go to its associated "x.1", i.e. the first instance of H1, open paragraph properties and manually untick the box for "Page break before".
Just like Darrin Koltow solution in this thread, this has its pros (no need for a separate style) and cons (still requires some manual work), and it is clearly a matter of preference.
I really cannot see why this is not a built-in feature though. I've managed to find this and this to prove uservoice is the official channel for requests, but don't have time atm to look into this further.
add a comment |
My solution is:
- Tick the box for "Page break before" in the style properties for H2,
- For each instance of H1, go to its associated "x.1", i.e. the first instance of H1, open paragraph properties and manually untick the box for "Page break before".
Just like Darrin Koltow solution in this thread, this has its pros (no need for a separate style) and cons (still requires some manual work), and it is clearly a matter of preference.
I really cannot see why this is not a built-in feature though. I've managed to find this and this to prove uservoice is the official channel for requests, but don't have time atm to look into this further.
add a comment |
My solution is:
- Tick the box for "Page break before" in the style properties for H2,
- For each instance of H1, go to its associated "x.1", i.e. the first instance of H1, open paragraph properties and manually untick the box for "Page break before".
Just like Darrin Koltow solution in this thread, this has its pros (no need for a separate style) and cons (still requires some manual work), and it is clearly a matter of preference.
I really cannot see why this is not a built-in feature though. I've managed to find this and this to prove uservoice is the official channel for requests, but don't have time atm to look into this further.
My solution is:
- Tick the box for "Page break before" in the style properties for H2,
- For each instance of H1, go to its associated "x.1", i.e. the first instance of H1, open paragraph properties and manually untick the box for "Page break before".
Just like Darrin Koltow solution in this thread, this has its pros (no need for a separate style) and cons (still requires some manual work), and it is clearly a matter of preference.
I really cannot see why this is not a built-in feature though. I've managed to find this and this to prove uservoice is the official channel for requests, but don't have time atm to look into this further.
answered Feb 4 at 16:46
pateksanpateksan
364
364
add a comment |
add a comment |
Thanks for contributing an answer to Super User!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f524319%2fword-2010-page-break-before-h2-except-after-h1%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown