我正在尝试在下面的vba脚本中为PowerPoint幻灯片添加注释注释。这个想法是该脚本可用于向幻灯片添加“待检查的注释”。因此,我在一个显示菜单的小插件中对其进行了设置,因此添加了TBC,TBU,TBD注释。子程序会不时显示错误,并且不能总是完全发挥作用(我猜是因为我在代码中写的部分:
ActiveWindow.Selection.SlideRange.Shapes("Rectangle 4").Select
谁能协助我使脚本变得防弹。对该方法进行简短的解释将是很好的。这样,我就可以了解将来的情况。
最好,
到目前为止,这是我的整个脚本:
Sub InsertShape_TBC()
ActiveWindow.Selection.SlideRange.Shapes.AddShape(msoShapeRectangle, 575.5, 9.12, 124.75, 34.12).Select
With ActiveWindow.Selection.ShapeRange
.Fill.Visible = msoTrue
.Fill.Solid
.Fill.ForeColor.RGB = RGB(162, 30, 36)
.Fill.Transparency = 0#
.Line.Visible = msoFalse
End With
ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Select
ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Characters(Start:=1, Length:=0).Select
With ActiveWindow.Selection.TextRange
.Text = "[TBC]"
With .Font
.Name = "Arial"
.Size = 18
.Bold = msoFalse
.Italic = msoFalse
.Underline = msoFalse
.Shadow = msoFalse
.Emboss = msoFalse
.BaselineOffset = 0
.AutoRotateNumbers = msoFalse
.Color.SchemeColor = ppForeground
End With
End With
ActiveWindow.Selection.SlideRange.Shapes("Rectangle 4").Select
ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Select
ActiveWindow.Selection.SlideRange.Shapes("Rectangle 4").Select
ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Select
ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Characters(Start:=1, Length:=6).Select
ActiveWindow.Selection.TextRange.Font.Bold = msoTrue
ActiveWindow.Selection.TextRange.Font.Color.RGB = RGB(Red:=255, Green:=255, Blue:=255)
ActivePresentation.ExtraColors.Add RGB(Red:=255, Green:=255, Blue:=255)
ActiveWindow.Selection.Unselect
End Sub
这看起来像是由PPT早期版本中的宏记录器生成的代码。
首先,除非绝对必要,否则请不要选择代码中的任何内容(很少这样做)。请改用形状引用(如您在我为回答其他问题而发布的其他两个示例中所见)。
因为录制的宏假定您正在使用的矩形称为Rectangle 4,所以只有在已具有三个矩形的幻灯片上运行它时,该宏才起作用。所以与其:
Dim oSh as Shape
Set oSh = ActiveWindow.Selection.SlideRange.Shapes.AddShape(msoShapeRectangle, 575.5, 9.12, 124.75, 34.12)
' Notice that I removed the .Select from the end of your code.
' We don't want to select anything if we don't have to.
' Then
With oSh
With .TextFrame.TextRange
.Text = "[TBC]"
With .Font
.Name = "Arial"
.Size = 18
.Bold = msoFalse
.Italic = msoFalse
.Underline = msoFalse
.Shadow = msoFalse
.Emboss = msoFalse
.BaselineOffset = 0
.AutoRotateNumbers = msoFalse
.Color.SchemeColor = ppForeground
End With ' Font
End with ' TextRange
End With ' oSh, the shape itself
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句