2013-06-18 93 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

我的榮幸。說實話,我第三次做筆記時記下了筆記(在幾次忘記之後),這次我不得不查看筆記。 ;-) –