PDA

View Full Version : Get the "Line Number" of a textbox



Shrout1
07-20-2011, 10:40 AM
Back with more textbox questions!

I want to get the document "Line Number" beneath where my text box resides. The text boxes are being used as metadata tags to help navigate a document.

I want to be able to cull the text directly next to the textbox in order to display the first sentence on the userform. This will give the reader some context about the data tag.

Here is the code I use to create the textbox:

Private Sub cmdAddTag_Click()
Dim x As Single
Dim y As Single
Dim CS As Shape
x = Selection.Information(wdHorizontalPositionRelativeToPage)
y = Selection.Information(wdVerticalPositionRelativeToPage)
Set CS = ActiveDocument.Shapes.AddTextbox( _
msoTextOrientationHorizontal, x, y, _
1, 1)
CS.Select
CS.Height = 0
CS.Width = 0
'Available Tags are generated on userform activate and loaded into a list
Selection.Text = frmMetadata.listAvailableTags.Text & ", metataginfo"
Update_Existing_Tags
End Sub


How do I reverse this and derive the line value of the textbox? As the tags might be moved I need to generate the location of the textbox each time the macro is run. Lots of info on how to position the textbox, but not how to return the textbox position. Any help is appreciated!

Shrout1
07-20-2011, 12:53 PM
Ok as I work through fixing my own issues... Hopefully this will benefit someone else!

Dim BoxRange As Range

Set BoxRange = Selection.ShapeRange(1).Anchor

BoxRange.Select


This code snippet from http://www.ms-news.net/f4084/how-to-deselect-floating-text-box-171883.html moves the selection back to the text box's anchor. Problem is that the anchor doesn't always correspond to the text directly behind the textbox.

Trying to take my X & Y coordinates (generated in the first code-snippet)
x = Selection.Information(wdHorizontalPositionRelativeToPage)
y = Selection.Information(wdVerticalPositionRelativeToPage)

And use these to move the cursor to that X,Y position. Anyone know how to do that?