none
Help Automating Page Naming RRS feed

  • Question

  • I'm currently using Visio 2010 to create organizational charts using Excel imports. In order to better navigate the hundred odd page Visio doc I'd like to name pages based on the executive that appears at the top of that page, i.e. George Washington and his subordinates, page is named "George Washington."

    I am new to VBA automation and have made little headway in finding a way to tell Visio to rename the page using the shape name from the ShapeSheet. Is this even possible, if so does anyone know the coding that might accomplish it?Thanks!

    Wednesday, February 24, 2016 8:38 PM

Answers

All replies

  • Hi,

    Based on your description, I will move your case to MSDN for General Office Development:

    https://social.msdn.microsoft.com/Forums/en-US/home?forum=officegeneral

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.


    Regards,

    Emi Zhang
    TechNet Community Support


    Please mark the reply as an answer if you find it is helpful.

    If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    Thursday, February 25, 2016 9:18 AM
  • Hi esteban220,

    We could change page name by set Page.Name property.

    For example:

    Application.Documents(1).Pages(1).Name = "hello"

    After change the page name, we could get the page object by using its name.

    Application.Documents(1).Pages("hello").Name = "word"

    There are some events of document, you may let the logical in the PageAdded event.

    There is an article that may benefit you:

    # Sample VBA Macro (Visio)

    https://msdn.microsoft.com/en-us/library/office/ff766902(v=office.14).aspx

    Regards

    Starain


    Friday, February 26, 2016 3:21 AM
    Moderator
  • Hi Starain,

    Thanks for the reply! So if I wanted to use another variable as the new page name, would "hello" become the variable executive name from that specific page? If so, what would be the command to do that?

    Wednesday, March 2, 2016 4:16 PM
  • Hi esteban220,

    Not so clear about it, but we could define the variable, then specify the value (base on other object or other), then modify the page name.

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, March 3, 2016 2:18 AM
    Moderator
  • I think I follow. Do you know how I could find that object name? And could you help with how I'd put all the code together? Here's an example, I want to rename the page "George Washington" and other pages using the employee at the top of the page.
    Thursday, March 3, 2016 4:34 PM
  • Hi esteban220,

    You could get first shape’s text, then based on it to rename the page name, for example:

    Dim vsoCharacters1 As Visio.Characters
    Dim t As String
        Set vsoCharacters1 = Application.ActiveWindow.Page.Shapes.ItemFromID(1).Characters
        vsoCharacters1.Begin = 0
        vsoCharacters1.End = 10
        s= vsoCharacters1.Text
    Application.Documents(1).Pages(1).Name = s

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, March 4, 2016 1:45 AM
    Moderator
  • Starain,

    Thank you so much! Last question, is there anyway for the Begin and End of the returned name to match the exact length of the shape name, for example "George Washington" (exact length) instead of "George Was" (10)?

    Monday, March 7, 2016 5:29 PM
  • Hi esteban220,

    Just remove the code of specifying Begin and End property.

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, March 8, 2016 2:21 AM
    Moderator
  • Hi Starain,

    After playing with it I finally figured it out, this being the code that when viewing the first page, returns the correct value. How do I know apply this to multiple pages?

    Sub Test()
    
        Dim vsoCharacters1 As String
        Dim s As String
            vsoCharacters1 = Application.ActiveWindow.Page.Shapes.ItemFromID(1).Cells("Prop.Name").ResultStr(visUnitsString)
            s = vsoCharacters1
        Application.Documents(1).Pages(1).Name = s
        
        
    End Sub
    
    If I go to another page, it renames the first page using data from the second
    Tuesday, March 8, 2016 7:40 PM
  • Hi esteban220,

    For this code: Documents(1).Pages(1), it is the first page, so you need to change the index of the page (e.g. page(2))

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, March 9, 2016 1:39 AM
    Moderator