0

简报 2010

我正在尝试选择循环中的每个新形状。但并非循环中的所有形状都被选中。始终只选择最后一个形状。怎么了?

谢谢

Private Sub AddShapeRectangleOnSelectedText()

  Dim oText As TextRange
  Dim linesCount As Integer
  Dim myDocument As Slide
  Dim i As Integer
  Dim s As Shape

  ' Get an object reference to the selected text range.
  Set oText = ActiveWindow.Selection.TextRange
  Set myDocument = ActiveWindow.View.Slide
  linesCount = oText.Lines.Count

  For i = 1 To linesCount
    Set s = myDocument.Shapes.AddShape(msoShapeRectangle, _
    oText.Lines(i).BoundLeft, oText.Lines(i).BoundTop, oText.Lines(i).BoundWidth, oText.Lines(i).BoundHeight)

    With s
     .Select
     .Fill.Visible = msoTrue
     .Fill.Solid
     .Fill.ForeColor.RGB = RGB(255, 255, 153)
     .Fill.Transparency = 0.7
     .Line.Visible = msoFalse
     .Line.Transparency = 0#
    End With
  Next

结束子

4

1 回答 1

0

Select有一个可选参数来指示选择是否应该替换先前的选择...

你可以像这样修改你的代码

.Select IIf(i = 1, True, False)
于 2013-03-25T21:22:21.647 回答