我刚刚编写了以下函数来创建并返回一个powerpoint对象:
Public Function Open_PowerPoint_Presentation(ByVal ppName As String) As Object
Dim objPPT As Object
Dim Path As String
Path = ThisWorkbook.Path
Set objPPT = CreateObject("PowerPoint.Application")
objPPT.Visible = True
Open_PowerPoint_Presentation = objPPT.Presentations.Open Path & "\Reports\" & ppName & ".pptx"
End Function
但是最后一行(Open_PowerPoint_PResentation =
...)给了我一个"编译错误"而我只是不知道为什么。任何人都可以帮我吗?
答案 0 :(得分:0)
将行更改为:
Set Open_PowerPoint_Presentation = objPPT.Presentations.Open(Path & "\Reports\" & ppName & ".pptx")
将对象分配给变量需要Set
关键字,括号是将方法返回(在本例中为Open
)赋值给变量的语法的一部分。