• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA Center shape on screen from listbox selection

Nu2Java

Member
Hi All... I am using a VBA macro to hi-lite shapes on top of an image, which works fine along with also zooming the screen when that shape is selected and active on the screen. Can anyone tell me if there is a way to activate a shape and have the shape show up in the center of the screen? The 'ScrollIntoView' works well, but I really want to have it centered on the screen and I cannot find a way of doing that. Below is the piece of code I am using now. Thanks for any help or guidance.

Code:
Set sh = ActiveSheet.Shapes(ListBox1.Value)
If sh Is Nothing Then
MsgBox ListBox1.Value & " does not exist!"
Exit Sub
End If

ActiveSheet.Shapes.Range(Array(ListBox1.Value)).Visible = True

sh.TopLeftCell.Activate

ActiveWindow.Zoom = 180

Application.ActiveWindow.ActivePane.ScrollIntoView _
Left:=Range(sh.TopLeftCell).Left, Top:=Range(sh.BottomRightCell).Top, _
Width:=700, Height:=900, Start:=True
 
Hi, you can approximate the shape location according to the Height & Width of the VisibleRange property …​
 
So after playing around with this a bit more, I came to realize my need is a bit tricky. I have a large 'main' shape that fits what is viewable on the screen. I then have many small shapes that I am hiding and only showing when the listbox item is clicked. All the shapes are static and are placed in the position over the top of the main shape. The 'ScrollIntoView' works pretty well, but many times it shows the shape almost off of the screen. So I am wondering if there is a way for Excel to know where that small shape is and then zoom and center that position? I have been searching for this and can't seem to find this type of example.
 
Back
Top