Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / September 2007

Tip: Looking for answers? Try searching our database.

Aligning text

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Nowhere - 07 Sep 2007 17:36 GMT
I have found many examples of aligning text to the left or right of a
document using code such as the following

wrdSelection.ParagraphFormat.Alignment := wdAlignParagraphLeft;

But I want to align 2 elements of text on the SAME line one to the left
of the document and the other to the right of the document

Thanks in advance

Mike

--
Jay Freedman - 07 Sep 2007 18:29 GMT
Word (unlike WordPerfect) doesn't do that with paragraph alignment. Set the
paragraph to left alignment, and insert a right-aligned tab stop at the
right margin. Enter the left element, followed by a tab character, followed
by the right element. Here's a sample of code:

Sub demoLeftRight()
   Dim rightMarginLocation As Single
   With Selection.Sections(1).PageSetup
       rightMarginLocation = .PageWidth - .LeftMargin - .RightMargin
   End With

   With Selection.Paragraphs(1)
       .Alignment = wdAlignParagraphLeft
       .TabStops.ClearAll
       .TabStops.Add Position:=rightMarginLocation, _
           Alignment:=wdAlignTabRight
       .Range.Text = "left stuff" & vbTab & "right stuff"
   End With
End Sub

Note that if you're trying to do this in a header or footer, the default
styles for those areas (named Header and Footer) already have the tab stop
defined this way, so you don't have to do it in code.

Signature

Regards,
Jay Freedman
Microsoft Word MVP        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

> I have found many examples of aligning text to the left or right of a
> document using code such as the following
[quoted text clipped - 7 lines]
>
> Mike
Jay Freedman - 07 Sep 2007 18:52 GMT
Slight amendment: the Header and Footer styles also include a center-aligned
tab stop at the 3-inch location. If you don't need anything centered, you
can either include two vbTab characters in the middle of the string or have
the code remove the center tab stop.

> Word (unlike WordPerfect) doesn't do that with paragraph alignment.
> Set the paragraph to left alignment, and insert a right-aligned tab
[quoted text clipped - 31 lines]
>>
>> Mike
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.