Link to home
Start Free TrialLog in
Avatar of djamps
djamps

asked on

MS Word VBA Selection.Information

I am trying to expand the extremely limited "change bar" feature of MS Word XP using VBA.  I have documents with several layers of changes, so up to 6 different types of changebars must be used.  MS word only allows one type.  This script will look at a selected region's location, and create a custom changebar in the margin.

Selection.Information(wdVerticalPositionRelativeToPage) lets me vertically position the line WRT the selection.  Works great.  Since horizontal location of the line is constant (in the margin), again no problem here.

My only issue is getting the vertical location at the end of the selection.  Without this information, I have to manually enter the number of lines I want to extend the custom change bar.  Since line spacing and font height changes this further complicates the best "guess" of my script.  I have to manually tweak long bars =(

How can I grab the vertical position of the *end* of a selection, not just the top?

-Randy

Avatar of Steve Knight
Steve Knight
Flag of United Kingdom of Great Britain and Northern Ireland image

Good question.  How about:

tempselect=selection
selection.start=selection.End
Selection.Information(wdVerticalPositionRelativeToPage)
tempselect.select

Steve
(sorry, obviously you need to do something with the number returned by selection.information()...
Avatar of djamps
djamps

ASKER

selection.start=selection.end what I am looking for to get selection.information to yield the end value.  good job!

However, tempselect.select gives up.  "Runtime Error 424, Object required"

I think what you are trying to do here is restore the original selection.  Could you enlighten me here?

-Randy

ASKER CERTIFIED SOLUTION
Avatar of Steve Knight
Steve Knight
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of djamps

ASKER

selection.start=selection.end what I am looking for to get selection.information to yield the end value.  good job!

However, tempselect.select gives up.  "Runtime Error 424, Object required"

I think what you are trying to do here is restore the original selection.  Could you enlighten me here?

-Randy

Avatar of djamps

ASKER

Doh!  i don't know why it posted twice (probably because I hit refresh)... but anyways, thx you solved my problem.

-Randy
(Oops, BTW when you hit refresh this site re-posts the last comment you made... Just FYI, there is a Reload button top left to take place of refresh button when you are in a Question...)

Steve
LOL! Crossposting going on all over the place!  No problem, thanks for the points!

Steve