PowerPoint - Getting the original Shape from inside a Placeholder (programatically) - vba

I'll give an example with a SmartArt Shape, but it could be asked about other shapes too.
When I go over Slide.Shapes, one of the Shapes has:
Shape.Type=msoPlaceholder and Shape.PlaceholderFormat.ContainedType=msoSmartArt
Is there a way to get to the actual SmartArt Shape contained in the placeholder?

Late but in case anyone looks for an answer to this later:
On approach is to copy the placeholder shape. The copy will be a duplicate of whatever the .ContainedType of the placeholder was, not a placeholder itself.
This works in 2007 as well, btw.

Related

Pick up the format of a shape in an active slide

How can I use PowerPoint macro to pick up the format of shape(1) in an active slide?
I try this, but it doesn't work
Activewindows.ActiveSlide.Shape(1).pickup
Please help me.
I don't think Powerpoint has an active slide property like Excel has ActiveSheet, so you'll need to find the index of the active slide, which Powerpoint does provide:
ActiveWindow.View.Slide.SlideIndex
You can use that to get a reference to the slide with the slides collection:
ActivePresentation.Slides(ActiveWindow.View.Slide.SlideIndex)
and you can use that to get the shapes collection for that slide:
ActivePresentation.Slides(ActiveWindow.View.Slide.SlideIndex).Shapes
and you can get use the Type property of any shape in that collection:
ActivePresentation.Slides(ActiveWindow.View.Slide.SlideIndex).Shapes(1).Type
Type is going to return a value from the MsoShapeType enumeration, so you'll need to reference that to find out a friendly shape name, for instance, 13 is msoPicture. Here's a link to that:
https://learn.microsoft.com/en-us/office/vba/api/office.msoshapetype
And here is a link to the Powerpoint object model reference.
https://learn.microsoft.com/en-us/office/vba/api/overview/powerpoint/object-model
Hope that helps. Let me know if that works for you.

Detect if selected shape / table is in edit mode with VBA?

I'm trying to write a PowerPoint VBA macro that would act differently whether a shape is merely selected or is in edit mode (i.e. the cursor to edit the text is present, see image).
Is there a way to check this using VBA in PowerPoint? I haven't been able to find on this anything so far
My ultimate goal being:
If just the shape is selected, the macro will align the shape left
If the shape is in edit mode, the macro will align the text left (and leave the shape where it is)
Any help would be appreciated
Best
You can do this by using Selection.Type. If it returns 2, the shape is selected. If the insertion point is in the text, it will return 3:
Sub DetectShapeOrText()
MsgBox ActiveWindow.Selection.Type
End Sub
PpSelectionType enumeration (PowerPoint)

Using Microsoft PP Functions in vba code?

I wrote a vba macro for PowerPoint. All works well but I miss one step.
So far my macro ends by selecting a certain group of shapes on a slide. After it finishes I go back to PowerPoint and use the "Group" button to make a group out of the selected shapes.
How can I use this Micorsoft Group function in my code. I only manage to group all shapes on a slide to one group or I get an error.
I have tryed:
ActivePresentation.slide(1).shapes.selected.group
but that doesn't work.
I have read this:
How do I group a set of shapes programmatically in excel 2007 vba?
but several names of shapes are identical, so that doesn't really work. And I do not know how to store the indexnumber of a shape into a variable - which would be a second option to solve my problem.
Basically the Microsoft own functions does exactly what I would need now, right? I takes the shapes that are selected and groups them to a group. can I just call this function within my macro?
Many thanks for any help.
If you've got the shapes selected, then this should do it:
Activewindow.Selection.ShapeRange.Group
ActivePresentation.Slides(1).Shapes.Range(Array(2, 3, 4)).Group
ActivePresentation.Slides(1).Shapes.Range(Array("this", "that", "other")).Group
ActivePresentation.Slides(1).Shapes.Range(Array("this", 42, 3)).Group

Dynamically update text in powerpoint using VBA

I have a report that is generated in PowerPoint, and underneath many of the graphs, there is text that tells the reader to refer to pages in the appendix. I would like to be able to dynamically reference these slides.
For example, under a graph I might have the text "Please see appendix page 54", but I need the 54 to be linked to a slide so that if I insert another slide it will say 55.
Is this possible to do in VBA? I do not expect somebody to write my code for me, I would just like to know if this is a reasonable thing to do before I spend hours attempting to do it.
Side note: I feel horrible asking a question about MS Office on here, but since I believe it would need to be implemented in VBA (I don't think this functionality is built in by default) I think that it is a relevant question.
No need to feel horrible asking this here.
How one might do this:
In PPT, shapes, slides and even the presentation itself can have an associated tag collection; named string values. For example, assuming a reference to the shape in oSh, you can do:
oSh.Tags.Add "AssociatedSlideId", "293"
In this case, you'd apply this tag to your graph; the 293 would be the SlideID of the slide you want to reference. Each slide has a unique SlideID assigned when it's created; the SlideID won't change when you move the slide around/add/delete slides.
To read the tag from the shape:
Debug.Print oSh.Tags("AssociatedSlideId")
In this case, that'd return "293". Feed that to FindBySlideID to get the SlideIndex of the slide (ie, the ordinal position of the slide in the presentation). Or ask it for SlideNumber if you want the number of the slide that'll appear in number placeholders (usually, but not always the same as slide index).
Debug.Print ActivePresentation.Slides.FindBySlideID(clng("293")).SlideIndex
You might also tag the textbox or other shape that you want to use to hold the reference, then write a function along the lines of:
Function ShapeTaggedWith(oSl as Slide, sTagName as String, sTagValue as String) as Shape
This would iterate through the shapes on slide oSl looking for one with a tag named sTagName, value = sTagValue and return it to the caller if found.
Now you can find the shape that's nominated as your caption for the graph, let's call it, and change its text to match the SlideIndex (or SlideNumber) of the slide the chart's supposed to reference.
Hope that's all moderately clear; if not, that's why the StackOverflow gods gave us comments.

Visio VBA Get BoundingBox of Text

I have a shape in Visio which is a group. The group shape can have its text edited, and when it's edited I want one of the child shapes to sit just to the right of the text in the group shape.
To do this, I created a VBA function that takes the group shape as an argument, and this gets called in the TextText event on the shapesheet.
So the routine simply calls BoundingBox(visBBoxUprightText) on the group shape to get the bounds of the text and locate the sub shape to the right of the bbox. But the bounds appear to be wrong. They're coming back sometimes well to the left or well to the right of the last character.
Is the visBBoxUprightText flag supposed to mean something other than getting rectangle coordinates around the rendered text characters?
EDIT:
Looking into it some more, I see that the BoundingBox method looks at the shape.type property to determine what the boundingbox encloses. If the shape type is visGroup then it's going to include the sub shapes as well, and there doesn't seem to be a flag to force it to consider the group as a simple shape.
So I guess now the question is, is there a way to get the BoundingBox of the text, ignoring sub-shapes? I tried putting a separate sub-shape to hold the text, and now it works like a charm.
Visio does not let you get the bounding box of the text while disregarding the text of sub-shapes in a grouped shape.