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:-
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.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
Kind regards,
Forrestgump1