Others

Create an SVG Icon from VBA Code in a PowerPoint Add-in

Emma BrownEmma Brown Nov 14, 2026 868 views

Question details

Create an icon from SVG source embedded in VBA so a PowerPoint add-in can be distributed without a separate icons folder.

Product
Microsoft PowerPoint VBA add-in
Device & OS
not provided
Scenario
The user is distributing a PowerPoint add-in as a PPAM file and wants its icon data included in the add-in.
Observed behavior
The desired result is an icon created from embedded source without distributing a separate SVG file.
Before you start

Check whether the icon is needed on a slide or as a Ribbon button image; these use different interfaces. For the temporary-file method below, use Windows PowerPoint with SVG insertion support and access to a writable temporary folder.

Solution 1Recommended

Embed SVG markup in VBA and insert it from a temporary file

Use this method to keep the SVG source in the PPAM while inserting an icon onto a slide without distributing an icons folder.

PowerPoint VBA cannot pass an SVG markup string directly to Shapes.AddPicture. The macro can write the string to a temporary SVG file, insert it without linking, and then delete the temporary file.

The example uses Windows COM components. SVG import support can vary by PowerPoint version and insertion method, so test it in the versions used by your add-in recipients.

1
Open the VBA editor

In PowerPoint, open the add-in source presentation, press Alt+F11, and choose Insert > Module.

2
Add the insertion macro

Paste the following example into the module and replace the sample SVG markup with your icon source. Escape double quotes in VBA strings by doubling them. Sub InsertEmbeddedSvg() Dim svg As String, path As String, message As String Dim fso As Object, stream As Object On Error GoTo Failed svg = "<svg xmlns=""http://www.w3.org/2000/svg"" viewBox=""0 0 100 100""><circle cx=""50"" cy=""50"" r=""40"" fill=""#4472C4""/></svg>" Set fso = CreateObject("Scripting.FileSystemObject") path = fso.BuildPath(Environ$("TEMP"), fso.GetBaseName(fso.GetTempName) & ".svg") Set stream = CreateObject("ADODB.Stream") stream.Type = 2 stream.Charset = "utf-8" stream.Open stream.WriteText svg stream.SaveToFile path, 2 stream.Close ActiveWindow.View.Slide.Shapes.AddPicture path, msoFalse, msoTrue, 50, 50, 100, 100 GoTo CleanUp Failed: message = Err.Description CleanUp: On Error Resume Next If Not stream Is Nothing Then stream.Close If Len(path) > 0 Then If fso.FileExists(path) Then fso.DeleteFile path End If On Error GoTo 0 If Len(message) > 0 Then MsgBox "Could not insert the icon: " & message, vbExclamation End Sub

3
Test and package the add-in

Select a slide in the presentation that will receive the icon, then run InsertEmbeddedSvg from the VBA editor. Verify that the icon appears and save the add-in source as a PowerPoint Add-In (.ppam).

Embed SVG markup in VBA and insert it from a temporary file
Slide icon versus Ribbon image: This macro inserts a picture on a slide; it does not supply a custom Ribbon button image. Ribbon images use a separate Ribbon customization mechanism.
Free Microsoft Office alternative

Create and edit presentations with WPS Office

WPS Office is a free, lightweight alternative for working with presentations in a familiar interface. Its Microsoft Office format compatibility makes it easier to move existing files, though it does not resolve PowerPoint PPAM or VBA add-in behavior.

Create and edit slide graphics in WPS PresentationOpen and save common Microsoft PowerPoint formats, including PPTXUse a familiar interface for an easier transition from Microsoft OfficeWork with a free, lightweight office suite
microsoft office alternative - wps office

Frequently Asked Questions

Can VBA insert an SVG directly from a string?

PowerPoint's Shapes.AddPicture expects a file path rather than SVG markup. One workaround is to store the markup in a VBA string, write it to a temporary SVG file, and insert that file.

Does the temporary SVG need to be distributed with the PPAM?

No. The SVG markup can be stored in the VBA module, and the macro can create the temporary file on the recipient's computer when needed. The computer must allow the macro to write to its temporary folder.

Will the inserted icon disappear when the temporary file is deleted?

The example calls Shapes.AddPicture with LinkToFile set to msoFalse and SaveWithDocument set to msoTrue, so the picture is embedded rather than linked. Verify the result in your target PowerPoint version.

Can the slide insertion macro provide a Ribbon button icon?

No. The macro adds a picture to a slide. A custom Ribbon button uses a separate Ribbon customization mechanism; for a built-in icon, you can use an imageMso identifier in the Ribbon XML.