Consulting

Results 1 to 10 of 10

Thread: Can not remove the picture holder (Bitmap) in the org chart shape

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Can not remove the picture holder (Bitmap) in the org chart shape

    Hi there,

    I am trying to automatically generate an org chart via Visio which is generated from excel data and them format it automatically. However I am stuck trying to remove the picture holder within the org chart shapes. The code I have so far is:-

    Sub DeleteAllBitmapsInContainers()
        Dim shp As Visio.Shape
        Dim page As Visio.Page
        ' Get the active page
        Set page = Visio.ActivePage
        ' Call recursive function to delete bitmaps
        DeleteBitmapsRecursive page.Shapes
        MsgBox "All bitmaps have been deleted from the page, including containers.", vbInformation
    End Sub
    
    
    Sub DeleteBitmapsRecursive(shapes As Visio.Shapes)
        Dim shp As Visio.Shape
        Dim shpIndex As Integer
        ' Loop through all shapes in reverse order
        For shpIndex = shapes.Count To 1 Step -1
            Set shp = shapes(shpIndex)
            ' Check if the shape is a bitmap (Picture)
            If shp.Type = visTypeForeignObject Then
                If shp.ForeignType = visTypeBitmap Then
                    ' Delete the shape
                    shp.Delete
                End If
            End If
            ' Check if the shape contains sub-shapes (e.g., container or grouped shape)
            If shp.Shapes.Count > 0 Then
                ' Recursive call for sub-shapes
                DeleteBitmapsRecursive shp.Shapes
            End If
        Next shpIndex
    End Sub
    I have tried searching for books on Visio VBA but there doesn't seem to be much on the subject. I have excel VBA experience but I can't work it out. As always any help is greatly appreciated.

    Kind regards,

    Forrestgump1
    Last edited by Aussiebear; 02-19-2025 at 01:41 PM. Reason: Edited code tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •