Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Aligning text to the right in a Macro in MS Word 1

Status
Not open for further replies.

timnicholls

Technical User
Oct 31, 2003
43
0
0
AU
Hi All,

I've just a basic macro attached to a toolbar button in Word and it works well.
I have enclosed it below. BUT...I want it to be aligned to the right!!

Like a letter head on the top right hand corner of a letter.

At the moment the code places it on the left hand side.

Can anybody help?
Thanks

Tim


Selection.TypeParagraph
Selection.InlineShapes.AddPicture FileName:= _
"C:\My Documents\Sandbox.jpg", LinkToFile:=False, SaveWithDocument:=True
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeText Text:="Jane Doe"
Selection.TypeParagraph
Selection.TypeText Text:="General Manager"
Selection.TypeParagraph
Selection.TypeText Text:="Sand Box Entertainment
Selection.TypeParagraph

 
Hi timnicholls,

If you right-align the first paragraph, the rest should follow it, so just add this at the beginning ..

[blue]
Code:
Selection.ParagraphFormat.Alignment=wdalignparagraphRight
[/blue]

Enjoy,
Tony

------------------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading FAQ222-2244 before you ask a question.
 
Have a try with putting
ActiveDocument.Paragraphs.Alignment = wdAlignParagraphRight
before your selectio block and
ActiveDocument.Paragraphs.Alignment = wdAlignParagraphLeft
after it.

Andreas Galambos
EDP / Technical Support Specialist
(andreas.galambos@bowneglobal.de)
HP:
 
Great Tony,

It works.

Then

Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft

After the section to get it back to the left for the rest of the text...

Thanks
Tim
 
You were faster and better, Tony. That's what I was looking for... :-D
 
OK Tony and MakeItSo,

Thanks again both of you.

How about the problem of left aligning text on the right.
See the example below is left aligned and should be on the right side of the letter.

Any ideas?

ABN 10 111 222 333
34 Grey Street
Adriatic Way Vic 3211
Phone: (00) 11111111
Fax: (00) 22222222
email:noone@test.org


The code so far is :



Selection.ParagraphFormat.Alignment = wdAlignParagraphRight
Selection.TypeParagraph
Selection.InlineShapes.AddPicture FileName:= _
"C:\My Documents\sandbox.jpg" LinkToFile:=False, SaveWithDocument:=True
Selection.TypeParagraph
Selection.TypeParagraph
Selection.TypeText Text:="Jane Doe"
Selection.TypeParagraph
Selection.TypeText Text:="General Manager"
Selection.TypeParagraph
Selection.TypeText Text:="Sandbox Entertainment"
Selection.TypeParagraph
Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
Selection.TypeParagraph
Selection.TypeParagraph


Tim
 
You could use
With Selection.ParagraphFormat
.LeftIndent = CentimetersToPoints(11.75)
.SpaceBeforeAuto = False
.SpaceAfterAuto = False
End With

before your text insertion and

With Selection.ParagraphFormat
.LeftIndent = CentimetersToPoints(0)
.SpaceBeforeAuto = False
.SpaceAfterAuto = False
End With

after it.
You'll have to play around a bit with the CentimetersToPoints value for the Indent though...
;-)

Andreas Galambos
EDP / Technical Support Specialist
(andreas.galambos@bowneglobal.de)
HP:
 
BTW - Do it as I did:
Hit Tools - Macros - record,
position the Indent ruler to the desired position and hit the macro stop button... ;-)
 
Ahhh...the recorded Macro.

You are the smartest boy in class :)

And you beat Tony!

Thanks I will try it.

Tim
 
Hi Tim,

Beaten fair and square [smile]

I was going to suggest the same, but the general case is much more complex because, until you have ALL the paragraphs (or at least the longest) you don't know where you want to align them to - and even then it's not easy.

Enjoy,
Tony

------------------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading FAQ222-2244 before you ask a question.
 
[lol]
Hahaha - nope, can't beat Tony that easily...

44.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top