How can I obtain the name of each page in each file and the number of graphic components in the corresponding page?

Rex Lau 20 Reputation points
2023-08-16T10:13:22.3166667+00:00

I have hundreds of visio files, each with several pages and several graphic components on each page. How can I obtain the name of each page in each file and the number of graphic components in the corresponding page?

Visio
Visio
A family of Microsoft products used to create diagrams and vector graphics.
99 questions
Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,970 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jiachen Li-MSFT 32,056 Reputation points Microsoft Vendor
    2023-08-17T01:46:27.4766667+00:00

    Hi @Rex Lau ,

    You can use Microsoft.Office.Interop.Visio Namespace.

    Check if the following code works for you.

    Imports Microsoft.Office.Interop.Visio
    
    Public Class Form1
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim processor As New VisioProcessor()
            processor.ProcessVisioFiles("C:\YourFolderPath")
    
        End Sub
        Public Sub ProcessVisioFiles(folderPath As String)
            Dim visioApp As New Application()
            visioApp.Visible = False
    
            Dim files As String() = IO.Directory.GetFiles(folderPath, "*.vsd*", IO.SearchOption.TopDirectoryOnly)
    
            For Each filePath As String In files
                Dim doc As Document = visioApp.Documents.Open(filePath)
                Console.WriteLine("File: " & filePath)
    
                For Each page As Page In doc.Pages
                    Console.WriteLine("Page Name: " & page.Name)
                    Dim shapesCount As Integer = page.Shapes.Count
                    Console.WriteLine("Number of Shapes: " & shapesCount)
                Next
    
                doc.Close()
            Next
    
            visioApp.Quit()
        End Sub
    End Class
    

    Best Regards.

    Jiachen Li


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.