Need macro to shift to left margin and then indent twice

R

RichardOnRails

I've got the following snippet in my macro that sets the font I want,
the backgroud I want, etc. What it doesn't do is move the selected
text to the left margin so that the two indents function properly.

When I first record the operations I wanted, the InchesToPoints
argument was (-0.4) or something like that; I can't remember exactly
what it was. I changed it to (-2.0), I think, with the expectation
that it would move the text exactly to the left margin.

However, the way it's coded now, the text get's shoved to the left
margin and ignores the two indents. Is there a way to say "shift to
the left margin" so the the two indents function properly?

Here's my problematic part of my macro:

With Selection.ParagraphFormat
.LeftIndent = InchesToPoints(-2#)
.SpaceBeforeAuto = False
.SpaceAfterAuto = False
End With
Selection.Paragraphs.Indent
Selection.Paragraphs.Indent


Thanks in Advance,
Richard
 
S

Suzanne S. Barnhill

If you must have a macro, you would do much better to have one that applies
a style defined with the appropriate font, indents, etc.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
http://word.mvps.org

message
news:97a7ba0c-72e9-485a-bdbc-93405f87e974@m13g2000yqb.googlegroups.com...
 
R

RichardOnRails

If you must have a macro, you would do much better to have one that applies
a style defined with the appropriate font, indents, etc.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USAhttp://word.mvps.org

Hi Suzanne,

Thanks for responding.
If you must have a macro ...

I'm going to apply the same compound style to a number of line-groups
in many documents to distinguish code copied from a Command Window as
distinguished from comments about the code. Is there a better way than
using a macro?
you would do much better to have one that applies
a style defined with the appropriate font, indents, etc.

Link what? I want code lines to be indented twice, have Courier New 10
point font, and have light-gray background. Where would I get styling
that you recommend. How would I get styling that you recommend?

I posted a snippet of my macro previously. The entire macro is
presented below.

Best wishes,
Richard

Sub IndentCourier10GrayIt()
'
' IndentCourier10GrayIt Macro
' Macro recorded 2/4/2011 by RLMuller
'
Selection.Font.Name = "Courier New"
Selection.Font.Size = 10
With Selection.ParagraphFormat
.LeftIndent = InchesToPoints(-2#)
.SpaceBeforeAuto = False
.SpaceAfterAuto = False
End With
Selection.Paragraphs.Indent
Selection.Paragraphs.Indent
With Selection.ParagraphFormat
With .Shading
.Texture = wdTextureNone
.ForegroundPatternColor = wdColorAutomatic
.BackgroundPatternColor = wdColorGray10
End With
.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
.Borders(wdBorderRight).LineStyle = wdLineStyleNone
.Borders(wdBorderTop).LineStyle = wdLineStyleNone
.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
.Borders(wdBorderHorizontal).LineStyle = wdLineStyleNone
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
End Sub
 
S

Suzanne S. Barnhill

All of the properties included in your macro can be defined as part of a
style. You can assign a keyboard shortcut to that style if desired. See
http://www.shaunakelly.com/topic/word/styles, specifically
http://www.shaunakelly.com/word/styles/ApplyAStyle.html and
http://www.shaunakelly.com/word/styles/ModifyAStyle.html

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
http://word.mvps.org

message
If you must have a macro, you would do much better to have one that
applies
a style defined with the appropriate font, indents, etc.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USAhttp://word.mvps.org

Hi Suzanne,

Thanks for responding.
If you must have a macro ...

I'm going to apply the same compound style to a number of line-groups
in many documents to distinguish code copied from a Command Window as
distinguished from comments about the code. Is there a better way than
using a macro?
you would do much better to have one that applies
a style defined with the appropriate font, indents, etc.

Link what? I want code lines to be indented twice, have Courier New 10
point font, and have light-gray background. Where would I get styling
that you recommend. How would I get styling that you recommend?

I posted a snippet of my macro previously. The entire macro is
presented below.

Best wishes,
Richard

Sub IndentCourier10GrayIt()
'
' IndentCourier10GrayIt Macro
' Macro recorded 2/4/2011 by RLMuller
'
Selection.Font.Name = "Courier New"
Selection.Font.Size = 10
With Selection.ParagraphFormat
.LeftIndent = InchesToPoints(-2#)
.SpaceBeforeAuto = False
.SpaceAfterAuto = False
End With
Selection.Paragraphs.Indent
Selection.Paragraphs.Indent
With Selection.ParagraphFormat
With .Shading
.Texture = wdTextureNone
.ForegroundPatternColor = wdColorAutomatic
.BackgroundPatternColor = wdColorGray10
End With
.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
.Borders(wdBorderRight).LineStyle = wdLineStyleNone
.Borders(wdBorderTop).LineStyle = wdLineStyleNone
.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
.Borders(wdBorderHorizontal).LineStyle = wdLineStyleNone
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
End Sub
 
R

RichardOnRails

All of the properties included in your macro can be defined as part of a
style. You can assign a keyboard shortcut to that style if desired. See
http://www.shaunakelly.com/topic/word/styles, specifically
http://www.shaunakelly.com/word/styles/ApplyAStyle.html and
http://www.shaunakelly.com/word/styles/ModifyAStyle.html
--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USAhttp://word.mvps.org

Hi Suzanne,

Thanks for your additional response. I apologize fore my belated
response. I didn't notice your content (repeated above) because it
was obscured (to my eyes) by repetition of material posted
previously. I will study the sites you reference and surely improve
my approach to macros and keyboard shortcuts.

Best wishes,
Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top