I'm building a PowerPoint VSTO addin where I store a lot of metadata on the presentation.
I'm currently storing it as XML as either manipulating AddIn.Application.ActivePresentation.CustomXMLParts for global data and Slide.CustomerData for slide specific information.
The problem is that neither of them is represented on the Undo/Redo stack. I can make a quintrillion changes to the presentation and modify my Custom XML at the middle somewhere, undo everything and still read back the XML I have last set.
Since I want my modifications to be Undo/Redoable, the best I could think of is storing the XML on a Shape and delete+recreate it on every modification. The problem with this is that the user can obliviously delete the shape or the slide the shape is stored on.
I need something less visible (to prevent accidental removal) and - preferably global - object on the presentation that I can store my XML on that is deletable/recreatable and modifies that Undo/Redo stack.
Is there something like this?
Or is there a better way to do this?
To answer my own question:
There is Tags!
When you add something to it with Tags.Add("Name", "Value") it is properly undoable, unlike CustomerData or CustomXMLParts.
Tags is present on the presentation and on the slides so both of my scenarios are covered.
Related
I refer specifically to the 2016 version, but this should also apply to 2013 and 2010.
----- TLDR Summary
Is it possible to use VBA to add a new Slide Master using a method
that I haven't found?
Is it possible to use VBA to access or manipulate the Layouts of
Slide Masters other than the first one in a Presentation object?
I suspect that the answer to both is "No" and that MS has merely
screwed up the exposure of the underlying objects, but others may
know more about programming PPT than me.
------ The Whole Question
Microsoft has deemed PowerPoint unworthy of a macro recorder for lo these many versions (I think it was dropped in either 2003 or 2007 from memory), so no help can be obtained from there.
The linked MSDN "help" item is woeful. It states that the property returns a Master object, though that isn't relevant for the moment.
An Office support page describes a slide master here. A Slide Master seems to be where the presentation's Slide Layouts live, presumably in the SlideMaster's CustomLayouts property, though it's interesting to note that only the first 9 of those CustomLayouts correspond to what you see in the GUI. (I count 11 CustomLayout objects in the SlideMaster in a new, blank presentation.) The numbers change if you add new layouts though the two vertical text layouts never seem to appear in the GUI list. This too is not the problem.
The problem is that you can in fact have more than one Slide Master per presentation by going to the View menu, Slide Master, and then selecting Insert Slide Master. Having multiple Slide Masters is discussed on the Office Support site here.
Frankly I regard this functionality as slightly broken because if you do that, then apply a Theme to the new Slide Master, you end up with a third Slide Master; the original under "Office Theme", a second under "Custom Design", and a third under the name of the Theme that you applied. This too is not in itself a problem. (Though it's worth noting that a Presentation does not have an AddSlideMaster method, which means that it does not seem to be possible to do this by VBA. Not that you necessarily want to, but if you did, you can't. There is only an .AddTitleMaster method which seems to be useless since all presentations have a TitleMaster as far as I can see and if a presentation has one then that method will error out according to the documentation.)
The problem is that the Presentation object does not have a collection of Slide Masters. It has only that one property, SlideMaster, which returns a single Slide Master / Master object.
Accordingly I can't see any way that you can programmatically add a new Slide Master. And even if you used one that is added through the GUI you can't seem to access any Slide Master except for the first one. And therefore you don't seem to be able to access, manipulate or assign any Layout from any Slide Master other than the first one to an individual slide.
Am I correct in this assumption, or am I missing something?
I shall offer thanks in advance even though that is often deleted from questions. Not that this one is likely to attract much attention; I suspect that there may be another Tumbleweed badge in my future.
Perhaps this page will be helpful in understanding it better - http://skp.mvps.org/2007/ppt003.htm
To avoid an XY problem, here's what I'm trying to accomplish: when a shape is selected, I want detail text about that shape to appear on the screen.
I first tried using Shape Data, but it supports only single-line name=value pairs. My detail information is an arbitrary, multiline text blob.
My next thought was to used the shape's ScreenTip (aka tooltip) to hold the text data, then write some VBA code to handle the _SelectionChanged event. When a shape is selected I want to copy it's ScreenTip text into the text of another object (my details panel).
I got the _SelectionChange event-handling working, but poking around the Selection object in the debugger I can't find any property of the selected object that exposes the ScreenTip information.
Is Visio's programming API too anemic to support his kind of thing? Is there another way I might be able to do this? Is there another tool that might be better for this (preferably free)?
Visio's API is capable of doing this, handily.
It seems you're not aware of Visio's shapesheet, which is where the screen tip text is stored, along with pretty much anything you'd want to know about a shape.
To access the screen tip text you simply read the Comment cell from the selected shape's shapesheet:
Application.Selection(1).CellsU("Comment").ResultStr(visNone)
This code will return the comment text.
You're on the right track using the SelectionChange event, though of course you're checking that the selection count = 1, or at least >0.
I am having a bear of a time finding an answer to what seems like a simple question. I am using Visio 2010. I need to have something like text box that I can update through VBA. I have to code to do it
shape.CellsU("Prop.Memory").Formula = """256 MB"""
for example (shape is a variable in this case). The problem is that I can't find out how to tie a control, like a text box or label, to a user defined property like "Prop.memory" in this case. I thought it might be a data graphic but adding a data graphic is disabled for me.
Michael.
I think that I have a solution. It is an odd one but it might work. The problem is that you cannot apply Data graphics when you have the master open in edit mode. what you can do is drop the master on the sheet based on the recordset. now you can add data graphics because it has a record source (I am guessing). I made the changes I need to that layout that I needed. I then dragged that shape to the stencil to become a new master. it will maintain the data links. it seems like an odd way to go about it but it does work. I might be good for now.
update: this didn't work for what I needed. I did find the way, though, on this site: Creating custom Visio shapes
Once you create the shape with the right fields, you have to use something like the following code to update it via VBA:
shp.cells("prop.Memory").Formula= chr(34) & "256 MB" & chr(34)
where shp is a visio shape
I just wanted to be the solution that I found is out there.
Cheers, Michael.
I want to show a waiting dialog, in the meantime all the calculations concerning with PowerPoint objects still are running in the background. My purpose is during the time dealing with PowerPoint objects, I try to prevent the user from interfering with the UI.
It seems that there is no way to deal with PowerPoint objects in the background. Is there any workaround for my case?
Thanks
Note: I am using VS Ultimate 2013, C#, PowerPoint 2013, vsto
Office applications use the single threaded apartment model. That's why you need to use the main thread for working with Office/PowerPoint objects. However, you can extract the required information into .Net collections and process the data on another thread.
But if you need to work with PowerPoint objects, a possible solution is to display a non-dialog form with a progress bar which display the state of your actions. Thus, end users will not be able to access the UI of PowerPoint. Don't forget to specify the parent window handle (PowerPoint window handle) for the Show method (see the IWin32Window interface).
Is it possible to programmatically change the selected master within a specific stencil document in Visio, using VBA? If so, how would I go about doing it?
It doesn't seem possible to use the Window.Select method, since that seems to only work in the drawing page...
With Visio API only it is only possible to get selected master(s) using the Window.SelectedMasters property, but not set it (it is a readonly property).
So, there is no direct solution.
If you are okay with (sort of) workaround, you can take a look at mine here (the same question):
http://visguy.com/vgforum/index.php?topic=3378.msg13172#msg13172
It simply sends keyboard keys to the stencil window right number of times :)