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
Related
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.
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:
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.
With PowerPoint 2007 & 2010, I have been trying to change the Type of Gradient Fill on a Shape object from default "Rectangular" to "Path" for days. Searched online but seems like no such question asked.
So far I can only get the Gradient Fill to be "Rectangle" (the default with 2 color gradient?). But I want it to be "Path". So far only able to do that by right click on the actual Shape --> Format Shape. "Format Shape" form shows and I can change the "Type:" from Rectangle to Path. But I want to do this change in VBA, anyone have a solution?
My code below. Variables starting with g are As Single
Set oSlide = ActivePresentation.Windows(1).View.Slide
With oSlide.Shapes.AddShape(msoShapeIsoscelesTriangle, gLeft, gTop, gWidth, gHeight)
.Line.Visible = msoFalse ' No Outline
.Adjustments(1) = gAdj1 ' Adjust the position of the pointing tip
.Rotation = gAngle ' Change the angle of Rotation
.Fill.Visible = msoTrue
.Fill.TwoColorGradient msoGradientFromCenter, 1 ' Enable Two Colour Gradient
.Fill.GradientStops(1).Color.RGB = RGB(255,255,255) ' Colour at center
.Fill.GradientStops(2).Color.RGB = RGB(121,121,121) ' Colour at edge
.Select
End With
Set oSlide = Nothing
If no VBA codes can achieve that, I will have to use workaround... Copy and Paste those Shapes from a Template file - this sounds bad as I am going to make it a PowerPoint AddIn.
Thanks in advance!
Patrick
I need to be able to copy shapes (chart, table, etc.) programmatically from one slide to another in PowerPoint 2007 keeping their original colors. The source and destination slides are in different presentations which have different themes.
These shapes might be complex and include a lot of colors, e.g., charts, tables, etc. The destination slide must maintain its theme, so I cannot simply copy the entire original slide colorScheme.
When copying a shape manually in PowerPoint, I get an option to "Keep Source Formatting". This copies all the original colors of the shape, converting theme colors into absolute RGB values.
What is the simplest way to do this programmatically?
You need to go to the slide and use Application.CommandBars.ExecuteMso
If you don't need to return to the previously selected slide afterwards, you can skip DoEvents and the second call to Application.CommandBars.ExecuteMso
It seemed like the position of the new shape was sometimes a little bit skewed after pasting, so I obtain a reference to the last shape in the Shapes collection of the second slide and copy the position of the original shape.
At least on my machine, without DoEvents, the macro would do nothing when I executed it (but it would work if I stepped through it).
Sub CopySelectedShapeToNextSlide()
Dim oShape As Shape
Dim oSlide As Slide
Dim nextSlide As Slide
Dim newShape As Shape
Set oShape = Application.ActiveWindow.Selection.ShapeRange(1)
Set oSlide = Application.ActiveWindow.Selection.SlideRange(1)
Set nextSlide = oSlide.Parent.Slides(oSlide.SlideIndex + 1)
oShape.Copy
Application.ActiveWindow.View.GotoSlide nextSlide.SlideIndex
Application.CommandBars.ExecuteMso "PasteSourceFormatting"
Set newShape = nextSlide.Shapes(nextSlide.Shapes.Count)
newShape.Left = oShape.Left
newShape.Top = oShape.Top
DoEvents
Application.ActiveWindow.View.GotoSlide oSlide.SlideIndex
Debug.Print newShape.Name
End Sub