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 / March 2005

Tip: Looking for answers? Try searching our database.

Set Tabs based on distance from right margin

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
singeredel - 28 Feb 2005 18:57 GMT
I need to set two tabs to the left of the right margin based on the length of
a string variable. This is what I have, but I don't know how to specify the
right margin in a variable. Please don't laugh too hard!  :D

       Dim CTab As Variant
       Dim CTab1 As Variant
       Dim CTab2 As Variant
       Dim sLen As Variant
       Dim sLen1 As Variant
       Dim sLen2 As Variant
       Dim sLen3 As Variant
       Dim sLen4 As Variant
       
       sLen1 = Len(PatientName$)
       sLen2 = Len(SSN$)
       sLen3 = Len(AttentionLine$)
       sLen4 = Len(DOE$)
       
       rMar = ?? establish right margin here
       
       CTab1 = rMar - Len(sLen) - (6 / 72)
       CTab2 = CTab1 - 0.15
       
       If sLen1 >= Len2 And Len1 >= Len3 And Len1 >= Len4 Then sLen = sLen1
       If sLen2 >= Len1 And Len2 >= Len3 And Len2 >= Len4 Then sLen = sLen2
       If sLen3 >= Len1 And Len3 >= Len2 And Len3 >= Len4 Then sLen = sLen3
       If sLen4 >= Len1 And Len4 >= Len2 And Len4 >= Len3 Then sLen = sLen4
       
       Selection.ParagraphFormat.TabStops.Add Position:=InchesToPoints(rMar
- CTab1), _
           Alignment:=wdAlignTabLeft, Leader:=wdTabLeaderSpaces
       Selection.ParagraphFormat.TabStops.Add
Position:=InchesToPoints(CurTab2), _
           Alignment:=wdAlignTabRight, Leader:=wdTabLeaderSpaces

Signature

singeredel(Julie)

Greg - 28 Feb 2005 19:22 GMT
How about:

rMar = ActiveDocument.PageSetup.RightMargin
singeredel - 28 Feb 2005 20:11 GMT
Doh! I am losing it! That gives me the right margin, but something else is
wrong in the code because it is not given me the tab position the length of
the string variable from the right margin.

> How about:
>
> rMar = ActiveDocument.PageSetup.RightMargin
Dave Lett - 28 Feb 2005 20:47 GMT
Hi Julie,

Selection.ParagraphFormat.TabStops.Add _
   Position:=InchesToPoints(rMar - CTab1), _
   Alignment:=wdAlignTabLeft, _
   Leader:=wdTabLeaderSpaces

The second line: was this supposed to be just CTab1, as in the following
(you use rMar to calculate a value for CTab1 a couple lines earlier)?
Selection.ParagraphFormat.TabStops.Add _
   Position:=InchesToPoints(CTab1), _
   Alignment:=wdAlignTabLeft, _
   Leader:=wdTabLeaderSpaces

And in the next block of code, you specify the position of the right-aligned
tabstop as CurTab2, but you've only defined CTab2, is this correct?

HTH,
Dave

> Doh! I am losing it! That gives me the right margin, but something else is
> wrong in the code because it is not given me the tab position the length of
[quoted text clipped - 3 lines]
> >
> > rMar = ActiveDocument.PageSetup.RightMargin
singeredel - 28 Feb 2005 21:05 GMT
Hi Dave,

I had defined  CTab1 = rMar - Len(sLen) - (6 / 72) previously. Was this
incorrect? You have it in the Add Tabstops section. Does this make a
difference? However, I get a run-time error 5149: The measurement must be
between -1584 pt and 1584 pt." I am wondering if it has to do with this
"Inches to Points" thing because I am already dealing with points, aren't I?
I couldn't find anything else that fit.

> Hi Julie,
>
[quoted text clipped - 24 lines]
> > >
> > > rMar = ActiveDocument.PageSetup.RightMargin
singeredel - 01 Mar 2005 01:55 GMT
Ignore the code in the last post and use the following:

       Dim CTab As Variant
       Dim CTab1 As Variant
       Dim CTab2 As Variant
       Dim sLen As Variant
       Dim sLen1 As Variant
       Dim sLen2 As Variant
       Dim sLen3 As Variant
       Dim sLen4 As Variant
       
       sLen1 = Len(PatientName$)
       sLen2 = Len(SSN$)
       sLen3 = Len(AttentionLine$)
       sLen4 = Len(DOE$)
       

       If sLen1 >= sLen2 And sLen1 >= sLen3 And sLen1 >= sLen4 Then sLen =
sLen1
       If sLen2 >= sLen1 And sLen2 >= sLen3 And sLen2 >= sLen4 Then sLen =
sLen2
       If sLen3 >= sLen1 And sLen3 >= sLen2 And sLen3 >= sLen4 Then sLen =
sLen3
       If sLen4 >= sLen1 And sLen4 >= sLen2 And sLen4 >= sLen3 Then sLen =
sLen4
       
       rMar = ActiveDocument.PageSetup.RightMargin
       CTab1 = Len(sLen + (6 / 72))
       CTab2 = CTab1 - 0.15
       
       
       Selection.ParagraphFormat.TabStops.Add _
           Position:=InchesToPoints(rMar - CTab1), _
           Alignment:=wdAlignTabLeft, _
           Leader:=wdTabLeaderSpaces
       
       Selection.ParagraphFormat.TabStops.Add _
           Position:=InchestToPoints(CTab2), _
           Alignment:=wdAlignTabRight, _
           Leader:=wdTabLeaderSpaces

> Hi Julie,
>
[quoted text clipped - 24 lines]
> > >
> > > rMar = ActiveDocument.PageSetup.RightMargin
Dave Lett - 01 Mar 2005 13:07 GMT
So you have everything working then?

> Ignore the code in the last post and use the following:
>
[quoted text clipped - 63 lines]
> > > >
> > > > rMar = ActiveDocument.PageSetup.RightMargin
singeredel - 01 Mar 2005 16:09 GMT
No...I get the error that it is outside the measurement range.

> So you have everything working then?
>
[quoted text clipped - 72 lines]
> > > > >
> > > > > rMar = ActiveDocument.PageSetup.RightMargin
Dave Lett - 01 Mar 2005 17:12 GMT
Hi Julie,

Well, not knowing what you're values are puts me in a difficult position. At
the end of your routine (before "End Sub"), add the following and let's see
what we get:

MsgBox "CTab1:" & vbTab & CTab1 & vbCrLf & _
   "CTab2:" & vbTab & CTab2 & vbCrLf & _
   "rMar - CTab1:" & vbTab & rMar - CTab1

This way, we can see which values are outside the measurement range.

Dave

> No...I get the error that it is outside the measurement range.
>
[quoted text clipped - 74 lines]
> > > > > >
> > > > > > rMar = ActiveDocument.PageSetup.RightMargin
singeredel - 01 Mar 2005 19:04 GMT
Hi Dave,

Thanks for your help. The values displayed were:
  CTab1 = 16
  CTab2 = 15.85
  rMar - CTab1 = 56

Obviously my logic is wrong. The right margin is set at 72 points (1") from
the right edge of the paper size of 8-1/2 x 11. It should probably be rMar +
CTab1. But the problem for me is how to convert this number to a tab location
based on points. Certainly CTab1 cannot be set at  70+16 or 86 points (86
points from the right margin maybe, but how do you write code to tell it
that?).

Thanks again!

Julie

Right now I am just using the following as strings to test:

       PatientName$ = "Smith, Joe"
       SSN$ = "555-55-5555"
       AttentionLine$ = "John Doe"
       DOE$ = "02/28/05"

> Hi Julie,
>
[quoted text clipped - 94 lines]
> > > > > > >
> > > > > > > rMar = ActiveDocument.PageSetup.RightMargin
Dave Lett - 01 Mar 2005 20:26 GMT
Hi Julie,

You have
rMar - CTab1 = 56

Both values are in points.

Then, the code has
Selection.ParagraphFormat.TabStops.Add _
   Position:=InchesToPoints(rMar - CTab1), _
   Alignment:=wdAlignTabLeft, _
   Leader:=wdTabLeaderSpaces

See the problem? You're inflating something (rMar - CTab1), which is already
in points (i.e., 56 points), by treating it as if it were in Inches.

HTH,
Dave

> Hi Dave,
>
[quoted text clipped - 119 lines]
> > > > > > > >
> > > > > > > > rMar = ActiveDocument.PageSetup.RightMargin
singeredel - 01 Mar 2005 21:03 GMT
I did try taking the InchesToPoints out previously and still got an error,
but perhaps it was due to something else. I tried removing it again and now
the tabs are set from the left margin at .22" and .78". So I guess I need to
figure the distance from the left margin?? round and round and round I go!  :D

> Hi Julie,
>
[quoted text clipped - 153 lines]
> > > > > > > > >
> > > > > > > > > rMar = ActiveDocument.PageSetup.RightMargin
 
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.