View Full Version : Solved: Scrolling to a textbox
Shrout1
07-18-2011, 01:44 PM
All,
I have a textbox 2 pages down in my document. The following code allows me to select the textbox:
'I have a list of all the textbox IDs on my form.
For Each Box In ActiveDocument.Shapes
If Box.ID = frmMetadata.listTagID.Text Then
Box.Select
End If
Next Box
This selects the textbox, but does not scroll down to it. I can't seem to find anything that will scroll the document to the textbox. Any help would be appreciated!
macropod
07-19-2011, 12:59 AM
Hi Shrout1,
Try:
ActiveDocument.Shapes(frmMetadata.listTagID.Text).TextFrame.TextRange.Selec t
Selection.Collapse
Shrout1
07-19-2011, 08:59 PM
Hi Shrout1,
Try:
ActiveDocument.Shapes(frmMetadata.listTagID.Text).TextFrame.TextRange.Selec t
Selection.Collapse
Absolutely brilliant! It snaps right into focus :)
The lesson I learned here is that I was trying to use ActiveDocument.Shapes.ID as my identifying marker. The code you wrote requires the ActiveDocument.Shapes.Name; the Name value acts as the index. So be aware that your "TextBox Identifier" must contain the Shapes.Name value and NOT the Shapes.ID
Thanks again! Now to bed... (probably sunny where you are...)
macropod
07-19-2011, 11:34 PM
Hi Shrout1,
You can use either the name or the ID #. From the code you posted, I couldn't tell which of these was returned by 'frmMetadata.listTagID.Text', but it really doesn't matter since either will work.
Shrout1
07-20-2011, 07:32 AM
Edit: See below as I believe I answered my own question :)
Macro: any way to make the routine 100% reliable? It seems that when I "select" certain text boxes Word will no longer scroll to the others.
Ex: I specify "textbox 14". Word scrolls to the location & the textbox is selected
Next I specify "textbox 12". Word selects the textbox but does not scroll to the location...
Shrout1
07-20-2011, 07:51 AM
I might have solved my own problem! Read that the selection object is notoriously flaky and unreliable. The recommendation was to create your own object and use that v. relying on the system objects. It appears that this has fixed it... though I may speak too soon! Here is my code and let me know if this looks good:
Dim Box As Shape
Set Box = ActiveDocument.Shapes(frmMetadata.listTagID.Text)
Box.TextFrame.TextRange.Select
In essence I just pass the properties of the active shape to the "Box" shape object and then base my "TextRange.Select" line on the "Box" object.
Crossing my fingers!
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.