2013-06-18 2 views
0

선택한 이미지의 크기를 조정하고 그에 따라 위치를 지정하고 그 아래에 2 개의 텍스트 상자를 만들고 마지막으로 이미지와 2 개의 텍스트 상자를 그룹화하는 코드를 만들고 싶습니다.VBA 파워 포인트 그룹화 배열?

내 전체적인 목표는 동일한 기능을 수행하지만 중간 및 오른쪽에 위치시키는 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

Perfect! 정말 고맙습니다!! :) – 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 

어떤 일이 벌어지고 있는지 살펴 봅니다. 셰이프 이름뿐만 아니라 셰이프에 대한 참조의 .Name 속성을 Array에 전달해야합니다.

+0

설명해 주셔서 대단히 감사합니다! – DaniDarko

+0

내 기쁨. 진실을 말하면서, 나는 이것을 (3 번 모두 잊어 버린 후에) 세 번 째 기록했고, 이번에는 내 노트를 찾아보아야 만했다. ;-) –