【问题标题】:How can I select each shapes in loop?如何在循环中选择每个形状?
【发布时间】:2013-03-15 12:10:09
【问题描述】:

PowerPoint 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

结束子

【问题讨论】:

    标签: vba powerpoint


    【解决方案1】:

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

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

    .Select IIf(i = 1, True, False)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-03
      • 2016-11-24
      • 2015-11-06
      • 1970-01-01
      相关资源
      最近更新 更多