[英]VBA open powerpoint save with new name
我试图简单地打开一个PowerPoint,然后使用新名称另存为。
我收到“编译错误:找不到方法或数据成员”
Public Sub OpenPPTfinalOpp()
Dim templatePath As String
Set PPT = New PowerPoint.Application
templatePath = ThisWorkbook.Sheets("Automation").Range("D20")
'templatePath = "C:\Users\[userName]\Desktop\test\Weekly Pack Update - Template.pptx"
PPT.Visible = False
Set PPT_pres = PPT.Presentations.Open(Filename:=templatePath)
Set PPT_pres = PPT.Presentations.SaveAs(Filename:="C:\Users\[userName]\Desktop\test\Weekly Pack Update - Final.pptx")
End Sub
代码运行时没有SaveAs行,理想情况下,我可以在不打开powerpoint的情况下运行此代码,因为这只是将其附加到电子邮件之前的第一步。
谢谢
从对问题的评论升级:
为此,对于任何文件类型,都无需打开Powerpoint: FileCopy
ThisWorkbook.Sheets("Automation").Range("D20"), "C:\\Users\\[userName]\\Desktop\\test\\Weekly Pack Update - Final.pptx"
要稍微更安全地执行此操作:
Public Function SafeCopy(Source As String, Destination As String) As Boolean
SafeCopy = False
'Source does not exist
If Len(Dir(Source)) < 2 Then Exit Function
'Clear destination file if it already exists
If Len(Dir(Destination)) > 1 Then
Kill Destination
'Cannot clear destination
If Len(Dir(Destination)) > 1 Then Exit Function
End If
'Do the actual copy
FileCopy Source, Destination
'Report on success/failure
SaveCopy = (Len(Dir(Destination)) > 1)
End Function
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.