PDA

View Full Version : How to change double-line spacing



vbwacky
01-31-2007, 08:59 AM
Hi there. I always got word documents with blank double line spacing between two paragraphs and have to delete one blank line manually. How can I use vba in word to scan the document and change blank double-line spacing to blank single line spacing?

Cheers.

fumei
01-31-2007, 09:43 AM
It would be better to use NO blank line spacing at all. If you use Styles, then all spacing is an attribute of the style, and no blank lines are needed.

This is the way Word is designed to be used, and I strongly urge you to use it this way.

However....sigh....With ActiveDocument.Content.Find
.Text = "^p^p^p"
.Replacement.Text = "^p^p"
.Execute Replace:=wdReplaceAll
End WithYou use three paragraph marks as the search because you need to include the ending paragraph mark of the paragraph that is followed by the two....sigh....empty paragraphs.

The point though, is these are not blank lines...they are empty paragraphs. Further, they have nothing to do with line spacing.

The code above will replace THREE paragraph marks in a row, with TWO paragraph marks in a row.

Again, this is still poor use of Word. It is still using an empty paragraph to make space between paragraphs with text. Proper style usage would have NO extraneous paragraph marks. There is no need whatsoever to use empty paragraphs to make space.

lucas
01-31-2007, 09:48 AM
Styles are kind of a mystery to many of us who don't use Word so much Gerry.....I see the advantages but the setup is a little daunting to many new users.

fumei
01-31-2007, 12:50 PM
What do you mean by "setup"?

The fact of the matter is, you ARE using styles. Even when you manually make format changes to a paragraph. Every single paragraph in Word has a style attached to it. Without exception. You can not have any text, any paragraph, without a style attached to it.

Why not take control and make them YOUR styles?

The advantages of using styles properly is huge. Format is consistent. You never have to use those empty paragraphs. You can globally change ALL paragraphs using a style by simply changing the style.

Say you have a 10 page document, and it has 40 instances of a specifically formatted paragraph. Say quotes that are formatted as indented 1.5 inches, italics and 11 pts.

Say you decide that you want the format to be 12 pts.

Choice A - There is no explicit style attached - Word has it as that dumb Normal + yadda yadda crap.

Action required: manually go through the document, selecting each of the 40 instances, and changing the font size to 12.

Choice B - the paragraphs have MyQuote style attached.

Actions required: ONE action is required. Modify the style to 12 pts.

Using the same example, but now you decide you want those quotes to be indented 2.2 inches, and the Font changed to Arial.

Choice A: selecting each of the 40 instances and use TWO separate dialogs (Format > Font - to change the font, and Format > Paragraph to change the indent).

Choice B: Modify the style.

Making, creating, Styles is not hard.

As far as I'm concerned, if every single document you ever make is unique, totally unique, - then OK, forget about styles.

But if you ever make a document even similar, use a template and in the template use Styles.

When you do use styles, processing is much easier in VBA.Dim oPara As Paragraph
For Each oPara In ActiveDocument.Paragraphs
If oPara.Style = "ThisStyle" Then
oPara.Style = "ThatStyle"
End If
NextBoom. Done. You change the format of every instance.

Real world example - and I have used this in development of templates.

Say you have - let's make it simple - a single page. It has four headings followed by body text. The body text is Times Roman 11 pts indented 1.5 inches, and you are wondering if it would be better if it was Arial 12 pts, and indented a wee bit more.

Style "BodyTextA" - Times Roman, 11 pts, indent 1.5 "
Style "BodyTextB" - Arial, 12 pts, indent 1.8"

Dim oPara As Paragraph
For Each oPara In ActiveDocument.Paragraphs
Select Case oPara.Style
Case "BodyTextA"
oPara.Style = "BodyTextB"
Case "BodyTextB"
oPara.Style = "BodyTextA"
End Select
NextPut up as a macro button on a toolbar, I can click the button and watch the text switch back and forth. I can see EASILY (one click - it toggles) what the document format would look like with the different attributes. Again, changing them manually would require going through two separate dialogs - Format > Font, and Format > Paragraph.

Just think, suppose you were using a border....ANOTHER dialog to go through.

Suppose you were using bullets....ANOTHER dialog to go through.

I guess my point is that yes, I will grant you that using Styles can take some initial effort. However, once you get the hang of using them, in the long run they make using Word much easier.

Again, I am not sure what you mean by "setup". Creating styles is not difficult at all.

lucas
01-31-2007, 02:42 PM
Point taken Gerry....I will be using your post to extend my understanding of styles, thanks. By setup I merly meant create as it turns out..or alter existing. Just shows how little I understood the concept of styles.

fumei
01-31-2007, 03:15 PM
If I can make a suggestion, when you are first building the style library for a document/template, use your building block style with "Style based on" set for "(no style").

I know this sounds a little confusing, so I will use another example.

A common style to set up is a main body text style. In fact it is usually the first one to be created. After all, all things considered, it will most likely be the most used style in the document.

You CAN, when creating a new style use "Normal" as the style the new style is based on.

Don't do this. Click the drop down for "Style based on", and scroll up to the top, and select (no style). Now format the style accordingly.

Another big hint: all styles have a property "Style for following paragraph". This can be VERY handy.

Say you have a question paragraph, followed by an answer paragraph.

Question style: Arial, 16 pts, Bold, Indent 1.0 ", SpaceAfter = 16 pts, Style for following paragraph = "Answer"

Answer style: Times Roman, 11 pts, Indent 1.8", SpaceAfter = 12 pts, Style for following paragraph = "Answer"

Now you can type the question (using the Question style), hit enter for a new paragraph....and viola!

There is automatically space between the paragraphs (16 pts), with the next paragraph automatically set for Answer and formatted as such.

Just keep typing. Hit enter...still answer style.

Ah....you say....what happens when I DON"T want another answer paragraph. I want to go back to MyBodyText...AND I want more space after than a regular Answer style - 20 pts vs 12 pts?

This is design, and you will find it very interesting watching the process.

Well, you make a AnswerLast style. Base it on Answer (so it uses the same font and font size/atributes), but change it to have SpaceAfter = 20 pts, and Style for following paragraph = MyBodyText (or whatever).

I do this often with bulleted lists. IN the list I like the spacing fairly tight, but I want more space after the LAST item - to put some space between the end of the list and the text of the next paragraph.

So I have BulletList2_End, which has the font attributes of BulletList2, but with additional SpaceAfter, and sets the following paragraphs style to my body text style.

In other words, my bulleted lists use TWO styles. One for all items except the last item, and one for the last item.

Actually, I will stop writing this stuff in this thread, as it is not really relevant, and the thread is going to wander down into the depths shortly.....

fumei
01-31-2007, 03:35 PM
Just for amusement sake....attached is a demo of the Flip Style macro I sometimes use.

You can click "Flip Style" on the menu bar. Notice the changes: font, font size, border, spacing after.....

Very, very, simply done with Styles.

fumei
01-31-2007, 03:40 PM
Lastly....BIG point....you can attach keyboard shortcuts to any style. This can speed things up immensely.

lucas
01-31-2007, 08:34 PM
Your time has not been wasted Gerry....I can see great advantages now to using the styles....I have been exploring the modify styles, etc. and making a few notes from your posts.....I will be handling things in Word much differently in the future. Thanks for taking the time.

fumei
02-02-2007, 03:49 AM
You are most welcome. I consider it time well spent if someone ends up trying to use Word the way it is designed to be used. Word has some very annoying aspects to it, and some times I tear my hair out because it can be really stupid in design. Yet....it IS a very powerful word processor, and DOES do things very well.

Styles are one of those things. Glad I could help.