Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1027
  • Last Modified:

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

0
djamps
Asked:
djamps
  • 5
  • 3
1 Solution
 
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
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
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
 
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now