Centering view on a shape

Started by phillip_141, December 11, 2015, 05:35:56 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

phillip_141

Hey guys,  I have another question. Is there some way to center the view on a particular shape from VBA? I'm dealing  with rather  large diagrams and I don't want to scroll all over the place looking for the one tiny shape that I want.


EDIT: 
Found some code that worked quite well for me!


Sub gotoShape(shp As Visio.Shape)
    Dim CenterSelectionOnZoom As Boolean
   
    If Not ActiveWindow.Page = shp.ContainingPage Then
        ActiveWindow.Page = shp.ContainingPage
    End If
   
    ActiveWindow.Select shp, Visio.visDeselectAll + Visio.visSubSelect
    CenterSelectionOnZoom = Application.Settings.CenterSelectionOnZoom
    Application.Settings.CenterSelectionOnZoom = True
    ActiveWindow.Zoom = ActiveWindow.Zoom
    Application.Settings.CenterSelectionOnZoom = CenterSelectionOnZoom
End Sub


The original post is http://visguy.com/vgforum/index.php?topic=6144.msg25098#msg25098 if you want to see more. 

Yacine

This question has been answered several times in the forum.
If the search function of the forum is not sufficient you may use google: "question site:visguy.com".
HTH,
Yacine
Yacine

phillip_141

Thanks Yacine, and sorry. I didn't even think about searching the forum first. I found nothing useful from standard google searches so I assumed there was nothing useful on the forums. I will specifically search the forums first in the future.

Yacine

#3
Cool 8) . Tell us - after having done your research work - if you still face difficulties.
Yacine

Thomas Winkel

Hi,

I guess you found the solution above in my topic:
http://visguy.com/vgforum/index.php?topic=6144.0

Did you also try Window.CenterViewOnShape?
This was suggested by Charly in the same topic.


Sub gotoShape(shp As Visio.Shape)
    ActiveWindow.CenterViewOnShape shp, visCenterViewDefault
End Sub

phillip_141

I actually did try that method, but it did not work for me.