PowerPoint Add-in directly access its object - vba

Powerpoint file is actually a zip file that contains xml sub-files. These sub-files illustrate all the properties of objects of every slides (e.g., position, color, animation, etc.). You can convert the pptx file into zip file and unzip it you will see sub xml files.
Now, I want to create a Powerpoint Add-in application, allowing me to add more information to a specific object, and store dynamically it in itself XML file (or when saving file as). For example, my Add-in PowerPoint application contains a button named "Flippable". When I select a specific object of a slide, and select "Flippable", my application will find the xml file that contains the object information, and add a tag "Flippable = true".
Is it possible to do that dynamically when running application?
Thanks

Why go to all the effort of cracking and parsing the XML file, assuming that you even can while he presentation's open in PPT, especially since you're already doing this from an add-in?
You mentioned that the user has selected a shape. Why not just tag the shape:
With ActiveWindow.Selection.ShapeRange(1)
.Tags.Add "Flippable", "Yes"
End With
You'd want a bit more code around that to make sure that there IS a selection, and if you want to allow tagging multiple shapes at one time, you'd need to put in inside a For Each/Next loop.
Then assuming a reference to the current shape to be tested in oSh
If oSh.Tags("Flippable")="Yes" Then
' Do your stuff
End If

Related

How to bundle my own images and call from function

I have built several custom add-ins for Powerpoint. I integrated them into PPT using Custom UI Editor for Office.
As part of this process, I could make my own icons for buttons, simply by 'Inserting' my own .png files into the PPT (presumably somewhere in the backend, if I were to unbundle the .zip. file which every PPT actually is.
Now, I want to create a button that allows users to easily insert country flag icons, which I can obtain in .svg format. How can I bundle these .svg or .png files into PPT, and call them from a module?
(I don't think it's the calling from module I have trouble with - I just don't know how to bundle the image files into the PPT.)
[EDIT] Alternatively, what I'm asking is this: How can I create an 'Insert Icons' interface that looks like what you get from Insert >> Icons?
(update: John Korchok's answer has made clear this is not possible)
[EDIT2] If you rename your powerpoint from .pptm to .zip```, you can see a folder inside the Zip file called ```ppt. Inside it, you get these folders:
Inside the media folder are EMF and WMF files created from pictures that were inserted into PPT (through the normal Insert Image function, or a simple Copy and Paste).
Is there a way I can write a function that calls images from within this folder?
There's no part of an Add-in where you might be able to store external files. I add a folder of images in the Add-ins folder, then create an installer that places the Add-in and folder in the correct locations.
You can also place the images on a web server and get PowerPoint to download them through VBA. Of course, you'll need a fast connection. The syntax looks like this:
Dim oPicture As Shape
Set oPicture = ActivePresentation.Slides(1).Shapes.AddPicture("http://www.brandwares.com/images/iconfile.png", False, True, 0, 0, -1, -1)

Visio macro to save a macro-free file

I have a series of complex charts to draw, so I have written a macro that takes a set of instructions from a CSV file and draws them appropriately. This works, but I need to manually save the produced page as a .vsdx file (i.e. without my macro code) after the fact.
What I'd like to do is specify the filename in the input file and have it produce a macro-free visio file of that name.
I've tried
Application.ActiveDocument.SaveAs filename
but this immediately generates a run-time error: "VB projects cannot be saved in macro-free files".
I understand that - I don't want my macro code in each of the (dozens of) flow charts I'm drawing. How can I suppress this error?
Thanks in advance.
If you want to have your macro(s) stored in a document file, then you'd want to have your macro generate a new document in which you draw your complex charts. But as #y4cine commented, you need to keep your code separate from your content, if you want to save your content as macro-free files.
Otherwise you may be able to set Application.AlertResponse to whatever response Visio asks interactively when you try to save a file that has a macro as a macro-free format.

PowerPoint Macro in a template

I am currently working on creating a template for a business presentation.
After the current client's name is written in the starting slide I want to be able to take it and place it on X amount of slides later created via a template, so that manual entry is almost completely reduced (this is a prerequest for the task).
Is it possible to create a macro so that it either edits the template slides after the needed information is written on the 1st slide or that it controls all the user created slides and labels afterwards?
What you're after is possible so long as the user can either install an add-in that you've written to do the job or open a file that you've saved as a PPTM rather than PPTX (ie, one with macros/vba included).

Placing a bitmap into a Powerpoint Add-In

All:
I am writing a PowerPoint add-in that will allow a user to drop specific safety related images onto a map. I've written the code that copies the images and places them on the slide and I would like to place it into an add-in. Unfortunately, I cannot find a way to either:
a) place the images into the add-in
b) reference images if I were able to place them in the add-in
The alternative approach is to require the user to start with a special template that includes all of the images and then load the add-in to get the menu functionality. I would much rather have a single file that contains both the code and bitmap images.
With best regards,
Walt
PPA files contain only code, not presentation content like images. As an alternative, you could distribute a PPT/PPTX that you open invisibly and extract the image you need.
After quite a bit of looking around I found a solution that resolves the problem adequately. Using Microsoft's Custom UI Editor, I created an XML entry in the PowerPoint Presentation that performs the Auto_Open function that would have been part of the Add-In. This allows me to add the menu functions that will be responsible for loading the specific images.
I've added a reference page at the beginning of the presentation that contains instructions on how to use the template... This page also contains all of the images that are used by the visual basic code. The 'Visible' flag on these images are set to False so the user does not see them. As they are copied from the reference page into the presentation, the Visible flag is set to True and they are pasted onto the current slide.
It is not a perfect solution, but it is adequate...

How to save options of a VSTO add-in in the currently open file?

I'm building a VSTO add-in for Powerpoint 2010 and the options the add-in sets apply to the currently open file instead of a per-user config. Can I save these options in the current file (I mean, add custom XML to the .PPTX file)? If so, how?
Thanks for your help.
For very simple data, custom properties are ok (so long as you're aware that anyone who opens the file will be able to see, edit and delete them). And note that because PPT shares a common, too-small, allocation of data between links and document properties, adding too many of one can wipe out the other.
I'd use tags instead. Every shape, slide and presentation object can have a tags collection, containing one or more Name / Value pairs of strings.
These are invisible to the user and will not interfere with the hyperlinks in the presentation.
' To add a tag
With ActivePresentation
.Tags.Add "MyTagName", "MyTagValue"
End With
' To use a tag
If ActivePresentation.Tags("MyTagName") = "MyTagValue" Then
' Do something or other
End If
If your Options are not too complex, I would go for Document Custom Properties. The following question illustrates how to use Custom Properties with Excel, they are supported in PowerPoint as well so this should provide a good starting point!