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

Started by ForrestGump1980, January 11, 2025, 11:24:43 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ForrestGump1980

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

Any help is greatly appreciated.

Yacine

I'm not sure about this, but doesn't the orgchart offer different templates - with and without picture.
Record a macro, change the style manually, then apply the relevant code lines to your macro.
Yacine

Nikolay

Org Chart shapes are controlled by Visio Org Chart solution. It is not recommended to mess with it. Visio Org Chart does not officially support automation.
Trying to do it anyway brings you to an uncharted territory and is likely to fail sooner or later. I would try to stick to the built-in capabilities or use some other solution that supports automation.

Anyway. To delete all org chart pictures (hack):
For Each s In ActivePage.Shapes
    ActiveWindow.Select s, visSelect + visDeselectAll
    Application.Addons("OrgC11").Run "/cmd=DeletePicture"
Next

Browser ID: smf (possibly_robot)
Templates: 4: index (default), Display (default), GenericControls (default), GenericControls (default).
Sub templates: 6: init, html_above, body_above, main, body_below, html_below.
Language files: 4: index+Modifications.english (default), Post.english (default), Editor.english (default), Drafts.english (default).
Style sheets: 4: index.css, attachments.css, jquery.sceditor.css, responsive.css.
Hooks called: 179 (show)
Files included: 34 - 1306KB. (show)
Memory used: 1065KB.
Tokens: post-login.
Cache hits: 13: 0.00147s for 26,548 bytes (show)
Cache misses: 3: (show)
Queries used: 17.

[Show Queries]