Textbox with rounded corners using VBA - vba

I have a predefined textbox in a PowerPoint slide, I need to make its corners rounded. Is there any way I can do this using VBA?

This example assumes that the shape you're after is the third shape on slide 1. Adjust accordingly:
Sub Test()
Dim oSh As Shape
Set oSh = ActivePresentation.Slides(1).Shapes(3)
With oSh
.AutoShapeType = msoShapeRoundedRectangle
.Adjustments(1) = 0.25
End With
End Sub
It converts the textbox to a rounded rectangle then sets the corners to be rounded. As far as I know, you cannot round the corners of a regular text box.

Related

Text not resized when changing slide size

I would have a noob question about PowerPoint resizing.
I have a slide in "On screen Show (16:9)" size that I need to resize in "Widescreen" size, which is still 16:9 ratio but not the same dimensions.
So I changed the "Slide Size" option : the pictures are well resized, but the text font size in texboxes has not been changed proportionnaly.
My initial slide looks like this :
before resizing
But after resizing, the text font size in textboxes has not been changed :
after resizing
Would anyone have a solution to resize the same way all the element of a slide, including text ?
Thank you in advance.
I try this VBA code to have all textboxes with the option "Shrink text on overflow" :
Sub Change()
Dim oSlide As Slide
Dim oShape As Shape
For Each oSlide In ActivePresentation.Slides
For Each oShape In oSlide.Shapes
oshape.TextFrame2.AutoSize = MsoAutoSize.msoAutoSizeTextToFitShape
Next oShape
Next oSlide
End Sub
But that unfortunately doesn't work.

VBA for Word, crop image to circle

i want to crop all images in my Word-document to a circle shape.
My current VBA is not doing anything. I am not quite sure how to do this. I found some VBA examples but not for Word (Power-Point)
My VBA at the moment is looking like this:
After looking more into it it seems my proble is that the images are inlineshapes?
Is there still any possible solution?
Sub Circles()
Dim allShapes As ShapeRange
Dim myShape As Shape
Set allShapes = Selection.ShapeRange
For Each myShape In allShapes
With myShape
.AutoShapeType = msoShapeOval
.Height = InchesToPoints(0.18)
.Width = InchesToPoints(0.18)
End With
Next myShape
End Sub
Cropping a picture to a circle is actually filling a shapes background with a picture.
Here is the code for doing that:
ActiveDocument.Shapes.AddShape msoShapeOval, 100, 100, 100, 100
ActiveDocument.Shapes(1).Fill.UserPicture ("Y:\Pictures\Mk45 Gun Proj_Blast.jpg")
The result:

VBA macro to increment rotation of selected shape/picture in powerpoint

Basically, I am not much of a programmer and do a lot of drawing and diagramming in PowerPoint for education purposes. I currently use PowerPoint 2016. To increase my workflow speed, I map keyboard shortcuts to macro keys on my keyboard so I get the functionality just by hitting a key on the keyboard.
I am trying to find a macro that I can link to a keyboard shortcut allowing me to increment the rotation of the currently selected shape to … let’s say 2 degrees each time I hit the shortcut.
I'm new to ppt vba. After doing some research so far here is what I came up with. But it doesn't seem to be working.
Public Sub RotateCW2()
Dim shp As Shape
Set shp = ActiveWindow.Selection.ShapeRange(1)
shp.Rotate = shp.Rotate + 2
End Sub
Appreciate the help!
After mix and matching things arround, I think this one is working.
Sub Rotate()
With ActiveWindow.Selection.ShapeRange
.IncrementRotation 2
End With
End Sub
and it works as intended. Thanks guys for your answers.
You were almost there. Try this instead:
Public Sub RotateCW2()
Dim shp As Shape
Set shp = ActiveWindow.Selection.ShapeRange(1)
shp.Rotation = shp.Rotation + 2
End Sub
From Thomas' answer I figured I might try this.
Public Sub RotateCW2()
Dim shp As Shape
Set shp = ActiveWindow.Selection.ShapeRange(1)
shp.Rotate = shp.IncrementRotation(2)
End Sub
This time I get the error "Compole error: Expected Function or variable" and it highlights (.IncrementRotation).
The Shape Object has a series of Increment properties to choose from.
Note: Descriptions copied from MSDN
IncrementRotation( Increment )
"Specifies how far the shape is to be rotated horizontally, in degrees. A positive value rotates the shape clockwise; a negative value rotates it counterclockwise."
IncrementRotationX( Increment )
"Specifies how much (in degrees) the rotation of the shape around the x-axis is to be changed. Can be a value from ? 90 through 90. A positive value tilts the shape up; a negative value tilts it down."
IncrementRotationY( Increment )
"Specifies how much (in degrees) the rotation of the shape around the y-axis is to be changed. Can be a value from ? 90 through 90. A positive value tilts the shape to the left; a negative value tilts it to the right."
Public Sub RotateCW2()
Dim shp As Shape
Set shp = ActiveWindow.Selection.ShapeRange(1)
shp.Rotate = shp.IncrementRotation 2
End Sub

Powerpoint Macro to center align a single text box to slide

I am trying to center align the text boxes in a large presentation. Each slide contains various shapes, but only has one text box with text in it, and I would like that text box aligned to the center of the slide. At the moment, I have a line of code that will make the text center aligned within its own text box, but I was wondering if there was a way of making the text box in the middle of the slide?
Sub TextSize()
Dim oSl As Slide
Dim oSh As Shape
With ActivePresentation
For Each oSl In .Slides
For Each oSh In oSl.Shapes
With oSh
If .HasTextFrame Then
If .TextFrame.HasText Then
.TextFrame.TextRange.Font.Size = 26.5
' change the code to make the text box centre aligned to the slide
.TextFrame.TextRange.ParagraphFormat.Alignment = ppAlignCenter
End If
End If
End With
Next
Next
End With
End Sub
Gopal's pointed you in the right direction. After your code to center the text, add this:
.Left = ActivePresentation.PageSetup.SlideWidth / 2 - .Width / 2
.Top = ActivePresentation.PageSetup.SlideHeight / 2 - .Height / 2
Although not mentioned, but in case you are adding the textboxes on the slide through VBA code (as explained in this documentation), then I guess textboxes do not have a property to directly get aligned to the slide in a particular fashion(in your case centrally).
Having said that, I would also point towards a possible workaround which may be to set the Top and the Left properties of the textboxes in a ratio proportional to the slide's height and width chosen for your presentation.
This I think should centrally align the textboxes.

Centering a Shape using VBA in PowerPoint 2003

I am programatically copying tables and graphs from Excel to PowerPoint.
Ideally, I'd like to center the graphs on the slide and resize them to fit the slide if necessary.
This shouldn't be too hard, and I can check & modify .Top, .Left, .Width, .Height of the shape just fine, but how do I find out the width/height of the slide itself to do the proper positioning?
The following will give you the Height and Width ...
Just divide by 2 :D
Sub a()
Dim a As Presentation
Set a = ActivePresentation
MsgBox a.PageSetup.SlideHeight, a.PageSetup.SlideWidth
End Sub
HTH