Need code to scroll to a shape (using top left or shape name)

QuantBurner

New Member
Joined
Jan 29, 2011
Messages
42
Hi,
I've written some code that places a large number of shapes on a worksheet. The code also names each shape. I'd like some code to show me how to scroll the window to a specific shape. I can easily get the top and left of the shapes location. But, how do I use that data to scroll to? is there a way to ust use the shape name?
Thanks!
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Hi,
I've written some code that places a large number of shapes on a worksheet. The code also names each shape. I'd like some code to show me how to scroll the window to a specific shape. I can easily get the top and left of the shapes location. But, how do I use that data to scroll to? is there a way to ust use the shape name?
Thanks!


Maybe something along these lines :

Code:
Sub Test()

    With ActiveSheet.Shapes("ShapeName")
        Application.Goto .TopLeftCell, True
        .Select
    End With

End Sub

Where ShapeName is the name of the target shape.
 
Upvote 0
Thanks. That does work. A couple quibbles though:
- That selects the shape and the user might move it then
- The shape ends up in the upper left. I was looking to have the shape centered in the wondow.

I came up with this:
dblTop = ActiveSheet.Shapes(strShapeName).Top
dblLeft = ActiveSheet.Shapes(strShapeName).Left
ActiveWindow.ScrollIntoView Left:=dblLeft + 300, Top:=dblTop - 150, _ Width:=100, Height:=200

This works O.K.

It appears that Excel will only scroll in whole unit cell/row increments so, I can't get the shape EXACTLY centered if my columns are wide/varying widths (which they are).

Cheers,
 
Upvote 0

Forum statistics

Threads
1,214,869
Messages
6,122,015
Members
449,060
Latest member
LinusJE

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top