gpt4 book ai didi

尝试设置 PowerPoint 幻灯片时出现 VBA 错误 "Expected Function or Variable"

转载 作者:行者123 更新时间:2023-12-04 21:34:05 25 4
gpt4 key购买 nike

我有以下代码 -

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 

任何帮助,将不胜感激。

最佳答案

按照我上面的评论,你不能SetSelect在同一行(此外,几乎没有任何理由使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com