Search code examples
c#vstovisio

How to access "page setup" properties in Visio using VSTO


Can anyone help me out with the above issue?. I have checked the Visio VSTO websites and could not find any codes that accesses the needed page properties.

  1. I need to access the "page setup" properties of the page using VSTO. and the following needs to be changed.
  2. Under the "Page Size" tab: Select Let Visio expand the page as needed.
  3. Under the "Printer paper" tab: need to change the change the size.

Much thanks.

enter image description here

            try
            {
                var pages = Globals.ThisAddIn.Application.ActiveDocument.Pages;

                foreach (var pg in pages)
                {
                    Microsoft.Office.Interop.Visio.Page page = (Microsoft.Office.Interop.Visio.Page)pg;

                    page. // ?? <- how to access the page setup??
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

Solution

  • I think these options are available in the PageSheet, and not directly exposed as properties of the "page" object. You can try this:

    page.PageSheet.Cells("PageWidth").Formula
    page.PageSheet.Cells("PageHeight").Formula
    page.PageSheet.Cells("DrawingResizeType").Formula
    

    enter image description here

    Also, there is Macro Recorder feature in Visio; when you are unsure how do a specific thing using API, you can turn it on, do that thing manually, and then examine the generated VBA code.