Visio Guy

Visio Discussions => Programming & Code => Topic started by: MartinSVK on January 27, 2023, 02:02:00 PM

Title: Change active page of Visio object in Excel
Post by: MartinSVK on January 27, 2023, 02:02:00 PM
I have an Excel document in which I inserted Visio object. It has a few pages, each page has a specific model and according to some checkboxes in excel I want to choose a specific page, so when I print the excel, it will have specific model from visio. All this should do via VBA code that will be trigered by checkmark. The Vision object is embeded in excel, I dont want to link an external document. So far I managed to activate the visio object, with this code:

Set visioObj = Worksheets("Document").OLEObjects("objekt 4")
visioObj.Activate

But I can't figure out, how to change the active page.

Do you have any idea how to do that?

Thank you.

I tried Application.ActivePage and visioObj.ActiveWindow.Page = visioObj.Pages("Strana-3") with no success.
Title: Re: Change active page of Visio object in Excel
Post by: Paul Herber on January 27, 2023, 03:49:47 PM
https://stackoverflow.com/questions/30646937/choose-active-page-in-visio
Title: Re: Change active page of Visio object in Excel
Post by: MartinSVK on January 27, 2023, 04:10:35 PM
Quote from: Paul Herber on January 27, 2023, 03:49:47 PM
https://stackoverflow.com/questions/30646937/choose-active-page-in-visio

Tried this:
    Set visioObj = Worksheets("Document").OLEObjects("objekt 4")
    visioObj.Activate
    vsPage = "Strana-3"
    visioObj.ActivePage = vsPage
and it's not working.
I am not opening vsd file in visio application, but only editing within excel, so can use the path option from your link.
I think the problem is that OLEobject does not allow editing.
Title: Re: Change active page of Visio object in Excel
Post by: Paul Herber on January 27, 2023, 04:57:56 PM
Your code is not the same as written in the example.
Title: Re: Change active page of Visio object in Excel
Post by: MartinSVK on January 27, 2023, 05:25:23 PM
Quote from: Paul Herber on January 27, 2023, 04:57:56 PM
Your code is not the same as written in the example.

Then I am afraid I don't understand what that code does. Would it be possible to let me know how to edit my code so it has the working parts from your example?

Would be very grateful.
Title: Re: Change active page of Visio object in Excel
Post by: Nikolay on January 27, 2023, 06:34:16 PM
Try this (the "visoObj" must be an embedded Visio document, i.e. a "Document" object)

    Set visioObj = Worksheets("Document").OLEObjects("objekt 4")
    visioObj.Activate
    vsPage = "Strana-3"
    visioObj.Object.Application.ActiveWindow.Page = vsPage

But the whole practice of modifying embedded objects programmatically looks so fragile, I would avoid it if possible  :)
Title: Re: Change active page of Visio object in Excel
Post by: MartinSVK on January 27, 2023, 10:21:46 PM
Quote from: Nikolay on January 27, 2023, 06:34:16 PM
Try this (the "visoObj" must be an embedded Visio document, i.e. a "Document" object)

    Set visioObj = Worksheets("Document").OLEObjects("objekt 4")
    visioObj.Activate
    vsPage = "Strana-3"
    visioObj.Object.Application.ActiveWindow.Page = vsPage

But the whole practice of modifying embedded objects programmatically looks so fragile, I would avoid it if possible  :)


Works perfectly, thank you very much.