?
Solved

MS Word VBA Selection.Information

Posted on 2003-02-28
8
Medium Priority
?
955 Views
Last Modified: 2008-02-01
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
Comment
Question by:djamps
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 43

Expert Comment

by:Steve Knight
ID: 8045184
Good question.  How about:

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

Steve
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 8045189
(sorry, obviously you need to do something with the number returned by selection.information()...
0
 

Author Comment

by:djamps
ID: 8045238
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
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
LVL 43

Accepted Solution

by:
Steve Knight earned 300 total points
ID: 8045271
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
 

Author Comment

by:djamps
ID: 8045279
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
 

Author Comment

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

-Randy
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 8045296
(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
 
LVL 43

Expert Comment

by:Steve Knight
ID: 8045297
LOL! Crossposting going on all over the place!  No problem, thanks for the points!

Steve
0

Featured Post

 [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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Office Picture Manager is not included in Office 2013. This comes as a shock to users upgrading from earlier versions of Office, such as 2007 and 2010, where Picture Manager was included as a standard application. This article explains how…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question