试图设置PowerPoint幻灯片时VBA错误“预期的函数或variables”

我有以下代码 –

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 

我得到一个错误

预期的function或variables

在下面一行:

 Set oPPTSlide = oPPTFile.Slides(SlideNum).Select 

任何帮助,将不胜感激。

按照上面的评论,你不能在同一行SetSelect (同样,几乎没有任何理由使用Select )。 尝试Set oPPTSlide = oPPTFile.Slides(SlideNum)

但是,对您的代码进行一些“升级”:

直接用新创build的Shapes设置oPPTShape

 Set oPPTShape = oPPTSlide.Shapes.AddTextbox(msoTextOrientationHorizontal, 10, 20, 300, 5) 

然后,使用下面的With语句轻松修改oPPTShape属性:

 With oPPTShape.TextFrame.TextRange .text = "ALL BSE" .Font.Color = vbWhite .Font.Underline = msoFalse End With 

应该…

 Set oPPTSlide = oPPTFile.Slides(SlideNum)