Visio Guy

Visio Discussions => Programming & Code => Topic started by: kgurr on July 23, 2021, 12:10:36 AM

Title: Position of the drawing page by VBA code
Post by: kgurr on July 23, 2021, 12:10:36 AM
Hello,
I have a question about the position of the drawing page.

When I save a Visio file and open it again, Visio will reopen the drawing page exactly with the position in the Visio window as I saved the file.

This means Visio remembers / saves the horizontal and vertical distance of the drawing to the window in the file... anywhere.

So far I have not been able to find these positions in Visio's object model!?

I would like to define these positions via VBA and am therefore looking for a way to do this... looking for the working VBA line.

I would be very grateful for a hint.
Title: Re: Position of the drawing page by VBA code
Post by: Surrogate on July 23, 2021, 02:21:01 AM
This means Visio remembers / saves the horizontal and vertical distance of the drawing to the window in the file... anywhere.
what you mean as anywhere?
Did you check properties of ActiveWindow object?
Title: Re: Position of the drawing page by VBA code
Post by: Yacine on July 23, 2021, 04:15:00 AM
Iterate over the pages of the document
  ActiveWindow.Page = tempPage
  ActiveWindow.ViewFit = visFitPage
Title: Re: Position of the drawing page by VBA code
Post by: wapperdude on July 23, 2021, 08:59:11 AM
Some additional Window related coding:
https://docs.microsoft.com/en-us/office/vba/api/visio.window (https://docs.microsoft.com/en-us/office/vba/api/visio.window)
https://docs.microsoft.com/en-us/office/vba/api/visio.window.zoom (https://docs.microsoft.com/en-us/office/vba/api/visio.window.zoom)
https://docs.microsoft.com/en-us/office/vba/api/visio.window.windowstate (https://docs.microsoft.com/en-us/office/vba/api/visio.window.windowstate)
Title: Re: Position of the drawing page by VBA code
Post by: Visio Guy on July 25, 2021, 05:47:58 PM
You can't depend on the size of the "next" Visio window that will see your document's page, but you can examine and control what is seen in the active window via:

Window.GetViewRect (https://docs.microsoft.com/en-us/office/vba/api/visio.window.getviewrect)
Window.SetViewRect (https://docs.microsoft.com/en-us/office/vba/api/visio.window.setviewrect)
Title: Re: Position of the drawing page by VBA code
Post by: wapperdude on July 25, 2021, 06:21:43 PM
@Visio Guy:  Ah choo!  I remember those.  Found them in a very dusty corner.  😱
Title: Re: Position of the drawing page by VBA code
Post by: kgurr on July 26, 2021, 12:58:37 AM
Hello,
thank you for your response  :)

"annywhere" means that the setting is obviously stored in the file (vsdx file), but I don't know where and how to access.

The second thing is, that this setting has nothing to do with the zoom factor. As shown in the screen shot, it is about the distance of the drawing sheet to the Visio window.

Therefore the commands
* visFitPage
* window.zoom
* window.windowstate
do not help... Nevertheless a mercy for the hint!


"SetViewRect" seems to be the right track, but I have not yet managed to find the working command...
There is no complete example for the command on the Microsoft command page.... at the moment I get an exception error.
I know that the windows variable needs to be of type "visDrawing" ... but I did not have the time to figure out how to work with this... yet.

Will test it further with SetViewRect... when I got the solution, I will get back.
Title: Re: Position of the drawing page by VBA code
Post by: Surrogate on July 26, 2021, 02:29:12 AM
Window.GetViewRect (https://docs.microsoft.com/en-us/office/vba/api/visio.window.getviewrect)
I try use this method in my code
Code
Public Sub SetWindowRect_Example()
 Dim vsoApplication As Visio.Application
 Dim vsoWindow As Visio.Window
 Dim pinLeft As Double, pinTop As Double, pinWidth As Double, pinHeight As Double
 Set vsoApplication = Visio.Application
 Set vsoWindow = ActiveWindow
 vsoWindow.GetViewRect pinLeft, pinTop, pinWidth, pinHeight
 Debug.Print pinLeft, pinTop, pinWidth, pinHeight
End Sub
Title: Position of the drawing page by VBA code - SOLVED
Post by: kgurr on July 27, 2021, 01:29:56 AM
Hello Surrogate,
this works perfectly.
 :)
Thank you for the support!