Create a new paragraph above or below the current paragraph.
What? Another one of these?
This is another one of those I wrote just because, but turns out, it’s one of my more used macros.
Thanks for your interest
This content is part of a paid plan.
Insert New Empty Paragraph
Huh? Isn't that what the Return key is for?
I'm talking about doing it faster.
Create the empty macro
A previous post covers creating an empty macro like the one shown below. When you’re done, you’ll have something like:
The single quote tells VBA the rest of the text on that line is a comment meant for human readers. We start our macro steps on the empty line.
Get current paragraph Range
We first access the current paragraph through the Selection as we've done before.
Then we get the corresponding Range (basically a span of document content with defined Start and End positions).
We’ve used this before for things like deleting the first paragraph.
Ranges, like other objects in VBA, have various properties (see introductory article) as well as methods or actions they can carry out on their content.
Insert the paragraph break
Insert the paragraph break after the current paragraph using its Range.
If we try to use InsertParagraph instead, it will delete the whole current paragraph.
Move to the new paragraph
Now we want to move down to the new paragraph, so we end on the empty paragraph ready for typing.
But the default move Unit is a line. As previously mentioned, this command works with a list of document Units, so we need to tell it to move by a paragraph
This move automatically collapses the Selection after the paragraph was inserted, and it works correctly no matter what our starting position is in the initial paragraph.
So we’re done!
New paragraph before current
We could use a variation of the above steps to create a variant for the previous paragraph, but there’s a subtle gotcha on the insertion point positioning that makes it a little more complicated than it seems at first.
It’s not too bad, but it’s still easier to just work with what we did last week when adding a new paragraph using the current sentence.
Make a couple tweaks and we’re done.
Previous new paragraph with sentence macro
In a previous macro, we created a new paragraph with the current sentence. If you didn't save it, here is a copy:
Tweak the macro for an empty paragraph
Change the unit on the starting move to a paragraph.
Get rid of the delete step since there is no space to delete.
Then collapse toward the Start of the Selection instead of the End since we want the insertion point to finish on the new empty paragraph.
That’s it.
Any gotchas?
The only real gotcha to consider here was related to the InsertParagraph method.
We just needed to make sure no text is selected before we include that step. Otherwise, it would overwrite the selected text with the new paragraph. The StartOf move step just before it automatically collapsed the selection for us (since we didn’t specify an Extend parameter), so we’re safe.
Finish the macro
Now we just put the commands together for each version.
For a new paragraph below the current one:
I assigned this one to Command+Control+Return in Word for Mac.
For a new paragraph above the current one:
I assigned this macro to Control+Option+Return in Word for Mac.
Improvements
I tweaked my own versions to modify the style of the new paragraph based on the expected “next” style of the current or previous paragraph, respectively.
Change the style of new paragraph
Why worry about it?
It’s definitely not required since the new paragraph will inherit the style of the current one, but it’s handy to control the exact style since you might run the macro while in a heading paragraph. For a heading paragraph, the next style should be different than the style of the current paragraph.
Setting a style
We can set the style of the new paragraph using:
Since we have an insertion point, it’s easier to just set the style using the shorthand property.
What style?
I would like the macro to respect the Next Paragraph Style property set in the style pane.
Save a step everywhere we can, and it doesn’t take much work to implement.
Storing and setting the expected style
For the version creating a new paragraph below the current, the next paragraph style is stored in the NextParagraphStyle property of the current paragraph style.
The easiest way is to just store the style before we create the new paragraph.
Then finally make the style adjustment when we’re on the new paragraph.
What about the before new paragraph version?
When inserting a new paragraph before the current one, I like to use the previous paragraph’s next paragraph style.
Say that three times real fast.
Here’s what I mean.
The Previous method for the Selection takes a Unit like several of the other commands we’ve used. We could use any of the Word units, but obviously we need the paragraph here.
We have to include the Unit in parentheses because we need to access the Style property after we have the previous paragraph.
Restated, I’m accessing the next style of the previous paragraph since that’s the position of the new paragraph I’m creating. If that’s confusing, just set the current style as you wish.
Finish the macros
Now we just put the commands together for each version.
For a new paragraph below the current one:
I assigned this macro to Command+Control+Return in Word for Mac.
For a new paragraph above the current one:
I assigned this macro to Control+Option+Return in Word for Mac.
I further created another variation to add a new paragraph at the end of the current heading (which I use to quickly append novel notes as I’m developing ideas), but that will have to be another newsletter.