Author Topic: Change active page of Visio object in Excel  (Read 374 times)

0 Members and 1 Guest are viewing this topic.

MartinSVK

  • Newbie
  • *
  • Posts: 4
Change active page of Visio object in Excel
« on: January 27, 2023, 09:02:00 AM »
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.
« Last Edit: January 27, 2023, 11:56:24 AM by Paul Herber »

Paul Herber

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3329
    • Paul Herber's website
« Last Edit: January 27, 2023, 11:56:33 AM by Paul Herber »
Electronic and Electrical engineering, business and software stencils and applications for Visio -

https://www.paulherber.co.uk/

MartinSVK

  • Newbie
  • *
  • Posts: 4
Re: Change active page of Visio object in Excel
« Reply #2 on: January 27, 2023, 11:10:35 AM »
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.
« Last Edit: January 27, 2023, 11:56:42 AM by Paul Herber »

Paul Herber

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3329
    • Paul Herber's website
Re: Change active page of Visio object in Excel
« Reply #3 on: January 27, 2023, 11:57:56 AM »
Your code is not the same as written in the example.
Electronic and Electrical engineering, business and software stencils and applications for Visio -

https://www.paulherber.co.uk/

MartinSVK

  • Newbie
  • *
  • Posts: 4
Re: Change active page of Visio object in Excel
« Reply #4 on: January 27, 2023, 12:25:23 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.

Nikolay

  • Hero Member
  • *****
  • Posts: 1154
    • UnmanagedVisio
Re: Change active page of Visio object in Excel
« Reply #5 on: January 27, 2023, 01:34:16 PM »
Try this (the "visoObj" must be an embedded Visio document, i.e. a "Document" object)
Code
    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  :)
« Last Edit: January 27, 2023, 05:46:08 PM by Paul Herber »

MartinSVK

  • Newbie
  • *
  • Posts: 4
Re: Change active page of Visio object in Excel
« Reply #6 on: January 27, 2023, 05:21:46 PM »
Try this (the "visoObj" must be an embedded Visio document, i.e. a "Document" object)
Code
    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.
« Last Edit: January 27, 2023, 05:45:53 PM by Paul Herber »