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

djampsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Steve KnightIT ConsultancyCommented:
Good question.  How about:

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

Steve
0
Steve KnightIT ConsultancyCommented:
(sorry, obviously you need to do something with the number returned by selection.information()...
0
djampsAuthor Commented:
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

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Steve KnightIT ConsultancyCommented:
Yup that is what I was /trying/ to do but failed miserably leaving the SET statement out and didn't check before posting (just typed it in...).  What I really meant was something more like:

Set tempselect = Selection.Range

Selection.Start = Selection.End
Debug.Print Selection.Information(wdVerticalPositionRelativeToPage)

tempselect.Select

which will take a copy of selection and change the selection to get the value you need then put the selection back (if you need to...)

Sorry for initial error!

Steve
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
djampsAuthor Commented:
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

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

-Randy
0
Steve KnightIT ConsultancyCommented:
(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
0
Steve KnightIT ConsultancyCommented:
LOL! Crossposting going on all over the place!  No problem, thanks for the points!

Steve
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Office

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.