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.
Related
I want to add a chart inside a textbox using VBA in Microsoft word.
I have tried using
ActiveDocument.InlineShapes.AddChart()
API;
with cursor inside the textbox and still it doesn't produce the desired result
Unless you specify where the chart is to be placed it will simply be added to the document. If you had looked at the help text, IntelliSense or the Object Browser you would have seen that the method takes a Range as an argument. To place the chart in a specific location the range is required.
For example:
Set shp = ActiveDocument.InlineShapes.AddChart(Range:=Selection.Range)
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)
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
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.
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.