Reputation: 33
I want to create a code that will resize a selected image, position it accordingly, create 2 text boxes beneath it, and finally group the image and 2 text boxes together.
My overall goal is to make 2 additional macros that will do the same function but position them in the middle and right.
I can't seem to figure out how to group the 3 shapes.
Here's my code below.
Dim LeftPic As ShapeRange, sld As Slide, ByeBox As Shape, HelloBox As Shape
Set LeftPic = ActiveWindow.Selection.ShapeRange
Set sld = Application.ActiveWindow.View.Slide
With LeftPic
.Left = 0.17 * 72 '72 is the multiplier for the inch
.Top = 1.83 * 72
.Height = 4.27 * 72
.Width = 3.2 * 72
End With
LeftPic.Name = "LeftPic"
Set HelloBox = sld.Shapes.AddTextbox(msoTextOrientationHorizontal, _
0.17 * 72, Top:=6.17 * 72, Width:=200, Height:=50)
HelloBox.TextFrame.TextRange.Text = "Hello"
HelloBox.Name = "HelloBox"
Set ByeBox = sld.Shapes.AddTextbox(msoTextOrientationHorizontal, _
0.17 * 72, Top:=6.42 * 72, Width:=200, Height:=50)
ByeBox.TextFrame.TextRange.Text = "Goodbye"
ByeBox.Name = "ByeBox"
Shapes.Range(Array("HelloBox", "ByeBox", "LeftPic")).Group
Upvotes: 0
Views: 3526
Reputation: 14809
I like ZebraOnWheels' approach for this problem, but more generally, you just need a bit of help with the syntax for Array (it's a bit improbable). Example:
Dim oSl As Slide
Dim TempArray() As Variant
Dim oGroup As Shape
Set oSl = ActivePresentation.Slides(1)
With oSl
TempArray = Array(.Shapes("Bob").Name, _
.Shapes("Carol").Name, _
.Shapes("Ted").Name, _
.Shapes("Alice").Name)
Set oGroup = .Shapes.Range(TempArray).Group
End With
See what's going on there? You have to pass Array the .Name property of references to shapes, not just the shape names.
Upvotes: 4
Reputation: 184
Dim LeftPic As ShapeRange, sld As Slide, ByeBox As Shape, HelloBox As Shape
Set LeftPic = ActiveWindow.Selection.ShapeRange
Set sld = Application.ActiveWindow.View.Slide
With LeftPic
.Left = 0.17 * 72 '72 is the multiplier for the inch
.Top = 1.83 * 72
.Height = 4.27 * 72
.Width = 3.2 * 72
End With
LeftPic.Name = "LeftPic"
Set HelloBox = sld.Shapes.AddTextbox(msoTextOrientationHorizontal, _
0.17 * 72, Top:=6.17 * 72, Width:=200, Height:=50)
HelloBox.TextFrame.TextRange.Text = "Hello"
HelloBox.Name = "HelloBox"
Set ByeBox = sld.Shapes.AddTextbox(msoTextOrientationHorizontal, _
0.17 * 72, Top:=6.42 * 72, Width:=200, Height:=50)
ByeBox.TextFrame.TextRange.Text = "Goodbye"
ByeBox.Name = "ByeBox"
sld.Shapes("HelloBox").Select
sld.Shapes("ByeBox").Select msoFalse
sld.Shapes("LeftPic").Select msoFalse
ActiveWindow.Selection.ShapeRange.Group
Upvotes: 0