2013-06-18 66 views
0

我想创建一个代码,它将调整所选图像的大小,相应地放置它,在它下面创建2个文本框,最后将图像和2个文本框分组在一起。VBA Powerpoint分组数组?

我的总体目标是制作2个额外的宏,它们将执行相同的功能,但将它们定位在中间和右侧。

我似乎无法弄清楚如何组合3个形状。

下面是我的代码如下。

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 

回答

0
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 
+0

完美!非常感谢!! :) – DaniDarko

2

我喜欢ZebraOnWheels'对于这个问题的办法,但更普遍的,你只需要一点点的帮助与语法阵列(这有点不可思议)。例如:

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 

看看那里发生了什么?您必须将Array的引用的.Name属性传递给形状,而不仅仅是形状名称。

+0

非常感谢你解释! – DaniDarko

+0

我的荣幸。说实话,我第三次做笔记时记下了笔记(在几次忘记之后),这次我不得不查看笔记。 ;-) –