PDA

View Full Version : Solved: Various changing of left margin



Mr Doubtfire
08-23-2005, 08:51 AM
Could anyone tell me how to (mulitple) change the left margin for Word.document through the code?
eg.
Sentence 1 here (first line)
Sentence 2 here (second line)
Sentence 3 here (third line)
Sentence 4 here (fourth line)

(Please note my ONLY concern is left margin)

Thanks.:think:

fumei
08-23-2005, 01:17 PM
Huh? Could you describe what you want to do. The tags here do not really allow sophisticated format in the posts.

If I am guessing correctly...some of those sentences are indented?

So are you asking about, say, a tab before a sentence, or are you asking about margins? Technically speaking "margins" generally are not directly connected to sentences...and by the way...do you actually mean paragraphs.

I know it is fussy, but with Word, when you mean paragraph...say paragraph.

So do you want to indent something, or really change margins? If it is jumping back and forth...do not change your margins.

Better yet....USE STYLES, USE STYLES, USE STYLES, USE STYLES.

Then...you can fo'gedda about it. The styles can take care of it.

Mr Doubtfire
08-23-2005, 06:22 PM
First, could you please show me how to change (lessen) the left margin?
Second, how to insert a tab (rather than entering " (spaces) " ) before the text?
I am interested to get the "STYLES" involved, would you be interested to show me how to "STYLE"?
Thanks.

geekgirlau
08-23-2005, 11:42 PM
First, could you please show me how to change (lessen) the left margin?

You don't actually change the margin for a single paragraph. If you want to reduce the left margin, you create a negative indent. To do this, select Format|Paragraph and set Left Indentation to a negative number. You can also accomplish the same thing by moving your mouse to the 2 triangles at the left margin on the ruler, and dragging them to the left.

Once you have worked out how to do this in a paragraph, record the steps in a macro to see the VBA code to use.


Second, how to insert a tab (rather than entering " (spaces) " ) before the text?

This one is also simplest to record as a macro. To move to the start of the current paragraph, press [Ctrl+Up Arrow], then press [Tab] to insert a tab.



I am interested to get the "STYLES" involved, would you be interested to show me how to "STYLE"?

A style is simply a way of storing formatting that you use frequently. For example, if you want your paragraph to have a reduced left margin and a tab on the first line, highlight your paragraph and select Format | Paragaph. Change Left Indentation to "-1.27cm", then change Special to "First line" and set By to "1.27cm".

After selecting OK, create your new style by typing a style name (such as "IndentPara") in the Style box on your Formatting toolbar (the style box will probably have the word "Normal" in it). Now to apply that formatting to any other paragraph in this document, click anywhere in the paragraph and select "IndentPara" from the Style drop-down list - no macro required.

fumei
08-24-2005, 12:05 AM
Uh.....oh boy.

1. "First, could you please show me how to change (lessen) the left margin?"

No, I will not. Record a macro doing it, and then look at the code. You can see for yourself.

2. Hmmmmm. Uh, please look in Help. There is a lot there, and you should really really be working this out yourself. Sigh, but here you go. It is....DA! DA! vbTab, as in:
Selection.Text = vbTab & "Hello"
will put a tab and the word Hello at the Selection point. Please also note that vbTab will tab at whatever is the current tab setting for the paragraph it is inserted into.

3. Styles? As far as I am concerned, anyone NOT using styles with Word is using Word badly. Period. Word is designed to use styles.

Styles are a huge subject, but can be simply stated as being the explicitly stated format and structure of a paragraph.

There are styles for paragraphs, characters, and with later versions of Word, for tables and lists. The main use of styles is with paragraphs.

You really must learn about what a paragraph actually means in Word.

Here is the simplest example of the use of styles. Documents without styles commonly have a paragraph, and then the person will press an "extra" Enter key. This is to make a space between paragraphs. As in:

paragraph text
"extra" Enter key
paragraph text
"extra" Enter key
paragraph text
"extra" Enter key

The Enter key makes a paragraph mark. Total paragraphs = 6.

USING a style, you can make that space an explicit part of the structure of the paragraph. As in:

paragraph text

paragraph text

paragraph text

Total paragraphs = 3.

So what? The following is what Word checks, line by line FOR EVERY SINGLE PARAGRAPH.
With Selection.Font
.Name = "Tunga"
.Size = 20
.Bold = False
.Italic = False
.Underline = wdUnderlineNone
.UnderlineColor = wdColorAutomatic
.StrikeThrough = False
.DoubleStrikeThrough = False
.Outline = False
.Emboss = False
.Shadow = False
.Hidden = False
.SmallCaps = False
.AllCaps = False
.Color = wdColorAutomatic
.Engrave = False
.Superscript = False
.Subscript = False
.Spacing = 0
.Scaling = 100
.Position = 0
.Kerning = 0
.Animation = wdAnimationNone
End With
With Selection.ParagraphFormat
.LeftIndent = InchesToPoints(0)
.RightIndent = InchesToPoints(0)
.SpaceBefore = 6
.SpaceBeforeAuto = False
.SpaceAfter = 6
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpace1pt5
.Alignment = wdAlignParagraphCenter
.WidowControl = True
.KeepWithNext = True
.KeepTogether = False
.PageBreakBefore = False
.NoLineNumber = False
.Hyphenation = False
.FirstLineIndent = InchesToPoints(0)
.OutlineLevel = wdOutlineLevelBodyText
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 0
.LineUnitBefore = 0
.LineUnitAfter = 0
End With
With ListGalleries(wdBulletGallery).ListTemplates(1).ListLevels(1)
.NumberFormat = ChrW(61623)
.TrailingCharacter = wdTrailingTab
.NumberStyle = wdListNumberStyleBullet
.NumberPosition = InchesToPoints(0.25)
.Alignment = wdListLevelAlignLeft
.TextPosition = InchesToPoints(0.5)
.TabPosition = InchesToPoints(0.5)
.ResetOnHigher = 0
.StartAt = 1
With .Font
.Bold = wdUndefined
.Italic = wdUndefined
.StrikeThrough = wdUndefined
.Subscript = wdUndefined
.Superscript = wdUndefined
.Shadow = wdUndefined
.Outline = wdUndefined
.Emboss = wdUndefined
.Engrave = wdUndefined
.AllCaps = wdUndefined
.Hidden = wdUndefined
.Underline = wdUndefined
.Color = wdUndefined
.Size = wdUndefined
.Animation = wdUndefined
.DoubleStrikeThrough = wdUndefined
.Name = "Symbol"
End With
.LinkedStyle = ""
End With
ListGalleries(wdBulletGallery).ListTemplates(1).Name = ""
Selection.Range.ListFormat.ApplyListTemplate ListTemplate:=ListGalleries( _
wdBulletGallery).ListTemplates(1), ContinuePreviousList:=False, ApplyTo:= _
wdListApplyToWholeList, DefaultListBehavior:=wdWord10ListBehavior
With Selection.ParagraphFormat
With .Borders(wdBorderLeft)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth050pt
.Color = wdColorAutomatic
End With
With .Borders(wdBorderRight)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth050pt
.Color = wdColorAutomatic
End With
With .Borders(wdBorderTop)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth050pt
.Color = wdColorAutomatic
End With
With .Borders(wdBorderBottom)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth050pt
.Color = wdColorAutomatic
End With
With .Borders
.DistanceFromTop = 1
.DistanceFromLeft = 4
.DistanceFromBottom = 1
.DistanceFromRight = 4
.Shadow = False
End With
End With
With Options
.DefaultBorderLineStyle = wdLineStyleSingle
.DefaultBorderLineWidth = wdLineWidth050pt
.DefaultBorderColor = wdColorAutomatic
End With

Say you have 50 paragraphs, and 50 "extra" Enter keys. 100 paragraphs. Words runs through all that stuff 100 times.

Say you have 50 paragraphs with the space built into the paragraph style. Word runs through all that stuff 50 times. Therefore Word runs faster, for example doing a repagination, using styles.

The other reason for using styles is that you get consistent format of documents. Every paragraph using the same style will have the same format and structure. If you change the style, every paragraph (using that style) in the document will change along with it.

In my own documents, I never do any manual format of text. I never use extra Enter keys. I never use Normal style.

Mr Doubtfire
08-26-2005, 04:48 PM
Very detailed.
Salute and thanks to ALL!

lucas
08-26-2005, 05:48 PM
Gerry you rascal, first you say your not gonna tell me then you give me the whole ball of wax.....Very nice explaination.:yes Thanks to geekgirlau also. Who needs a help file....

MOS MASTER
08-27-2005, 11:09 AM
Gerry you rascal, first you say your not gonna tell me then you give me the whole ball of wax.....Very nice explaination.:yes Thanks to geekgirlau also. Who needs a help file....

Yepz that's Gerry all the way!! Always a Rascal! :moosegrin