使用VBScript在powerpoint幻灯片中创建一条线并更改线条颜色

时间:2016-08-12 02:40:10

标签: vbscript

我想使用VBScript创建一条线,并在powerpoint幻灯片中将线条颜色更改为黑色。只是示例代码很好。感谢。

2 个答案:

答案 0 :(得分:0)

我录制了一条线然后更改了它的颜色。这是VBA代码。

    ActiveWindow.Selection.SlideRange.Shapes("Rectangle 3").Select
    ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Select
    ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Characters(Start:=1, Length:=0).Select
    With ActiveWindow.Selection.TextRange
        .Text = "Hi There" + Chr$(CharCode:=13)
        With .Font
            .NameAscii = "Arial"
            .NameComplexScript = "Arial"
            .Size = 32
            .Bold = msoFalse
            .Italic = msoFalse
            .Underline = msoFalse
            .Shadow = msoFalse
            .Emboss = msoFalse
            .BaselineOffset = 0
            .AutoRotateNumbers = msoFalse
            .Color.SchemeColor = ppForeground
        End With
    End With
    ActiveWindow.Selection.TextRange.Font.Color.SchemeColor = ppForeground
    ActiveWindow.Selection.TextRange.Font.Color.SchemeColor = ppAccent2

可以浓缩为

ActiveWindow.Selection.SlideRange.Shapes("Rectangle 3").Select
ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Select
ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Characters(Start:=1, Length:=0).Select
With ActiveWindow.Selection.TextRange
    .Text = "Hi There" + Chr$(CharCode:=13)
    With .Font
        .Color.SchemeColor = ppForeground
    End With
End With
ActiveWindow.Selection.TextRange.Font.Color.SchemeColor = ppForeground
ActiveWindow.Selection.TextRange.Font.Color.SchemeColor = ppAccent2

然后将其转换为无类型并使用后期绑定。还将命名参数转换为位置。用常量替换常量(在Powerpoint的对象浏览器中查找)。请注意,应用程序对象不是全局的,因此将pp.放在方法和属性之前。

Set PP = CreateObject("PowerPoint.Application")
pp.ActiveWindow.Selection.SlideRange.Shapes("Rectangle 3").Select
pp.ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Select
pp.ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Characters(1, 0).Select
With pp.ActiveWindow.Selection.TextRange
    .Text = "Hi There" + Chr$(13)
    With .Font
        .Color.SchemeColor = 2
    End With
End With
ActiveWindow.Selection.TextRange.Font.Color.SchemeColor = 2
ActiveWindow.Selection.TextRange.Font.Color.SchemeColor = 7

以上是有效的VBScript和VBA。

答案 1 :(得分:0)

我向您展示了如何将VBA的录制语法转换为标准VBA / VBScript。

记录您的操作,PowerPoint将为您完成。

Alt + T,M,R(以及停止录制的相同键)。按Alt + F11查看录制的代码。然后如上转换。

这是画线的powerpoint记录。

Sub Macro1()
'
' Macro recorded 15/08/2016 by User
'

    ActiveWindow.Selection.SlideRange.Shapes.AddLine(59.5, 219#, 671.88, 219#).Select
    With ActiveWindow.Selection.ShapeRange
        .Line.ForeColor.SchemeColor = ppForeground
        .Line.Visible = msoTrue
    End With
End Sub

所以用它们的值替换常量。使用createobject添加应用对象,如上文所述。