VBA Powerpoint: Can i hide shapes randomly on a slide? - vba

you can use VBA to hide shapes: VBA PowerPoint Display and Hide Shapes
But can you hide shapes randomly on a slide (all but one specific)?
I donĀ“t know how to make a random on a
ActivePresentation.Slides("Slide1").Shapes("Rectangle 1").Visible = False
I aspect, that i can hide a random shape on the actual slide by click(the Shape must have to be a visible shape before, so that another start of the code does hide randomly the next visible shape and not the hidden shape again).

Related

Difference between msoGraphic and msoPicture in Powerpoint shape types

When extracting shape type on PowerPoint slide using VBA the result is either msoGraphic or msoPicture for an Image shape.
What are the differences between these two types?

Visio VBA Return the 'Start' and 'End' of shape as values related to the Horizontal Ruler

I have a Visio drawing (and will have many more) that have a timeline e.g. months or quarters represented by boxes
[Example 'timeline'][1]
The drawing will have shapes that align to the 'timeline' and I need to read through the shapes and return the Shape Text and the Start and End ruler positions of shapes - from this I can ascribe a date and duration of sorts which is consumable elsewhere. I have failed to find a means by which to find Start and End positions of shapes that I can relate (consistently) to the ruler (or the shape timeline 'boxes').
The obvious, PinX and PinY values are not consistent (in relation to the ruler or other shapes). I have no control over the received drawings -so the ruler is the only constant.
Any help would be appreciated (whilst not at all new to VBA I am new to Visio VBA and there is a lot to it and a lot I do not understand).
[1]: https://i.stack.imgur.com/pMzC3.png
Problem was me, much as I hate to admit it. With all items Pin Pos Centre-Centre and LocPinX = width*0.5 this works. The actual measurement of the Ruler is irrelevant as the shapes do follow consistent positioning so that 'Start X' = PinX-(width/2) OR PinX - LocPinX and therefore 'EndX' = 'Start X' + Width.

Replace image in a shape, not add a new one

I have a VSTO written in VB.NET and want to maximize a selected image to the background. Documents tell me to remove the old shape and add a new one with AddPicture, but I have a template that includes image shapes already there and AddPicture puts the image in one of those shapes already there.
To prevent images from landing in the wrong shape I really just want to replace the original image with the resized one.
This is what I have:
dim src as PowerPoint.Shape = PowerPoint.Selection.ShapeRange.Item(1)
src.Export(file1, PowerPoint.PpShapeFormat.ppShapeFormatPNG)
dim img as Image = BitMap.FromFile(file1)
Then some image magic, and then:
img.Save(file2, PowerPoint.PpShapeFormat.ppShapeFormatPNG)
Dim _S As PowerPoint.Slide = ppApp.ActiveWindow.View.Slide
Dim _P As PowerPoint.Shape = _S.Shapes.AddPicture2(file2, MsoTriState.msoFalse, MsoTriState.msoTrue, 0, 0, _W, _H)
But that puts the image in the wrong template-shape.
Is there a way to actually replace the image in a shape without adding a new shape?
You can't insert an image inside a shape, only (in some cases) inside a placeholder, and you've mentioned that you specifically don't want to do that.
You can use an image to fill a shape, but unless you don't mind the image getting distorted, the aspect ratios of the image and the shape must match.
Suggestion: before adding the new image/shape, iterate through all the shapes on the slide looking for placeholder shapes. If any placeholder shape is of a type that can contain images (Content, Picture and Clip Art placeholders), fill it with dummy content (a few characters of text for Content, any random picture for the other two). Add your image; since the "image-capable" placeholders are already filled, the image will be added as a new shape. Then delete each of the shapes you've added dummy content to. When you delete a placeholder that has content, the content gets deleted and leaves the original empty placeholder behind.

How to change the shape selection on another slide?

How can I change the shape selection on another slide programmatically?
For example:
My current selection is on the shape 5 (the shape with id = 5) of the slide 3. How can I switch the selection on the shape 6 (the shape with id = 6) of the slide 2 programmatically?
Note: I am writing code in C#, VS Ultimate 2013, PowerPoint 2013

Capture which shape was clicked on in powerpoint

I have a PowerPoint presentation in which some slides contain multiple shapes for the user to click on.
I want to capture which shape is clicked. I am able to capture if shape has test on it using macro but what if it shape contains any image?
Every shape on a slide has a unique ID property that you can examine to determine which shape is selected.
Or you can add a tag to the shape beforehand:
ActiveWindow.Selection.ShapeRange(1).Tags.Add "MyName", "MyValue"
then
If ActiveWindow.Selection.ShapeRange(1).Tags("MyName") = "MyValue" Then
' Whatever