我有以下代码 -
Option Explicit
Sub main()
Dim oPPTApp As PowerPoint.Application
Dim oPPTObj As Object
Dim oPPTFile As PowerPoint.Presentation
Dim oPPTShape As PowerPoint.Shape
Dim oPPTSlide As PowerPoint.Slide
Dim oGraph As Graph.Chart
Dim oAxis As Graph.Axis
Dim SlideNum As Integer
Dim strPresPath As String, strNewPresPath As String
strPresPath = "Location.ppt"
strNewPresPath = "Destination.ppt"
'instantiate the powerpoint application and make it visible
Set oPPTObj = CreateObject("PowerPoint.Application")
oPPTObj.Visible = msoCTrue
Set oPPTFile = oPPTObj.Presentations.Open(strPresPath)
SlideNum = 1
Set oPPTSlide = oPPTFile.Slides(SlideNum).Select
Set oPPTShape = oPPTSlide.Add(1, ppLayoutBlank)
oPPTSlide.Shapes.AddTextbox msoTextOrientationHorizontal, 10, 20, 300, 5
With oPPTSlide.Shapes(1).TextFrame.TextRange
.text = "ALL BSE"
.Font.Color = vbWhite
.Font.Underline = msoFalse
End With
End Sub
我收到一个错误
Expected Function or Variable
在以下行:
Set oPPTSlide = oPPTFile.Slides(SlideNum).Select
任何帮助,将不胜感激。
最佳答案
按照我上面的评论,你不能Set
和 Select
在同一行(此外,几乎没有任何理由使用 Select
)。试试 Set oPPTSlide = oPPTFile.Slides(SlideNum)
但是,对您的代码进行了一些“升级”:
直接设置oPPTShape
与新创建的 Shapes
和 :
Set oPPTShape = oPPTSlide.Shapes.AddTextbox(msoTextOrientationHorizontal, 10, 20, 300, 5)
然后,轻松修改
oPPTShape
属性,使用 With
声明如下:With oPPTShape.TextFrame.TextRange
.text = "ALL BSE"
.Font.Color = vbWhite
.Font.Underline = msoFalse
End With
关于尝试设置 PowerPoint 幻灯片时出现 VBA 错误 "Expected Function or Variable",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43345320/