Question

I'm pretty rusty with VBA and I was hoping someone could point me in the right direction, or help me out. What I'm trying to do is run a macro that will cycle through each active container on my sheet, and then count the number of shapes within that container. Then I'd like to update a field in the shape data for the container with the number of shapes.

This is what I have so far:

Public Sub countContainers()
    Dim vsoPage As Visio.Page
    Dim vsoDocument As Visio.Document
    Dim vsoDocuments As Visio.Documents
    Dim vsoPages As Visio.Pages
    Dim vsoContainerShape As Visio.Shape

    Dim containerId As Variant

    For Each containerId In vsoPage.GetContainers(visContainerIncludeNested)
        Set vsoContainerShape = vsoPage.Shapes.ItemFromID(containerId)
        Debug.Print vsoContainerShape.NameU
    Next    
End Sub    

The error I get is Object Variable or With Block variable not set

Any ideas?

Was it helpful?

Solution

The error is because you have declared the vsoPage but you never assigned it to any page in your document.

Add a line such as this to initialize it and the error goes away:

Set vsoPage = ActivePage
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top