K
kamur
Hello, I am trying to find the spacewidth between words
in a text 'Justified' word document. I have two
approaches to find the spacewidth. Both the methods gives
different results eventhough the approach seemed okay in
both cases.
In one method, I am using:
Set rng = Selection.Range
For i = 1 To rng.Characters.Count
If rng.Characters(i) = " " Then
rng.Characters(i).Select
ActiveWindow.GetPoint pLeft, pTop, pWidth,
pHeight, rng.Characters(i)
MsgBox "Width = " & pWidth
End If
In the second method, the macro calculates the x,y of
last character of the first word and then the x,y of the
first character of the next word. He then subtracts the x
values to get the space width between 2 words. But I see
this value doesnot exactly equals the value from
SpaceWidth macro....I am not sure if it should match or
not....Can you see anything wrong with this approach. His
macro is:
Sub Macro3()
'
' Macro3 Macro
' Macro recorded 9/18/2003 by Jacob
'
Selection.MoveRight Unit:=wdCharacter, Count:=1,
Extend:=wdExtend
x = Selection.Information
(wdHorizontalPositionRelativeToPage)
y = Selection.Information
(wdVerticalPositionRelativeToPage)
MsgBox (x)
MsgBox (y)
Selection.MoveRight Unit:=wdCharacter, Count:=1
x1 = Selection.Information
(wdHorizontalPositionRelativeToPage)
y1 = Selection.Information
(wdVerticalPositionRelativeToPage)
MsgBox (x1 - x)
MsgBox (y1 - y)
End Sub
Why am I getting different results on these two methods?
Shouldn't I get the same result on both? If not, what is
wrong here..
Thanks
in a text 'Justified' word document. I have two
approaches to find the spacewidth. Both the methods gives
different results eventhough the approach seemed okay in
both cases.
In one method, I am using:
Set rng = Selection.Range
For i = 1 To rng.Characters.Count
If rng.Characters(i) = " " Then
rng.Characters(i).Select
ActiveWindow.GetPoint pLeft, pTop, pWidth,
pHeight, rng.Characters(i)
MsgBox "Width = " & pWidth
End If
In the second method, the macro calculates the x,y of
last character of the first word and then the x,y of the
first character of the next word. He then subtracts the x
values to get the space width between 2 words. But I see
this value doesnot exactly equals the value from
SpaceWidth macro....I am not sure if it should match or
not....Can you see anything wrong with this approach. His
macro is:
Sub Macro3()
'
' Macro3 Macro
' Macro recorded 9/18/2003 by Jacob
'
Selection.MoveRight Unit:=wdCharacter, Count:=1,
Extend:=wdExtend
x = Selection.Information
(wdHorizontalPositionRelativeToPage)
y = Selection.Information
(wdVerticalPositionRelativeToPage)
MsgBox (x)
MsgBox (y)
Selection.MoveRight Unit:=wdCharacter, Count:=1
x1 = Selection.Information
(wdHorizontalPositionRelativeToPage)
y1 = Selection.Information
(wdVerticalPositionRelativeToPage)
MsgBox (x1 - x)
MsgBox (y1 - y)
End Sub
Why am I getting different results on these two methods?
Shouldn't I get the same result on both? If not, what is
wrong here..
Thanks