0

我想创建一个代码来调整所选图像的大小,相应地定位它,在它下面创建 2 个文本框,最后将图像和 2 个文本框组合在一起。

我的总体目标是制作 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
4

2 回答 2

3

我喜欢 ZebraOnWheels 解决这个问题的方法,但更一般地说,您只需要一些有关 Array 语法的帮助(这有点不可能)。例子:

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 属性,而不仅仅是形状名称。

于 2013-06-18T18:44:14.607 回答
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
于 2013-06-18T17:03:40.380 回答