VB.NET: VBA PowerPoint 常量未声明
VB.NET: VBA PowerPoint constant not declared
我在使用 .NET Framework 4.7.2 的 Visual Basic 代码时遇到问题 运行。我正在使用 VBA for Office(文档)并尝试创建 PowerPoint 自动化工具。现在我遇到了 运行 问题,当我使用 SaveAs method for PowerPoint, the constant 时,我为参数 文件格式 提供的参数是 'not declared'。我相信我已经正确设置了所有引用。此外,SaveAs 方法通常有效,除非我尝试指定 文件格式 ,它会抛出此错误:
代码:
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
For Each sSourceFile As String In sFileLocations
Dim pptApp = CreateObject("PowerPoint.Application")
pptApp.visible = True
Dim sSourcePath = Mid(sSourceFile, 1, InStrRev(sSourceFile, "\"))
Dim sDestPattern = Mid(sSourceFile, InStrRev(sSourceFile, "\") + 1)
Dim sDestinationFile = Replace(sDestPattern, ".pptx", "", 1, -1, CompareMethod.Text)
sDestinationFile = Replace(sDestinationFile, ".ppt", "", 1, -1, CompareMethod.Text)
Dim pptPres = pptApp.Presentations.Open(sSourceFile)
' Debug.WriteLine(sSourcePath)
' Debug.WriteLine(sDestinationFile)
pptPres.SaveAs(sSourcePath & sDestinationFile & ".pptx", ppSaveAsDefault)
' Update PowerPoint thubmnail by adding new slide to the front then saving file
Dim pptLayout = pptPres.Slides(1).CustomLayout
Dim newSlide = pptPres.Slides.AddSlide(1, pptLayout)
pptPres.save()
' Remove new slide and save again to display correct thumbnail
Dim removeSlide = pptPres.Slides(1).Delete
pptPres.save()
pptPres.close()
pptApp.quit()
pptPres = Nothing
pptApp = Nothing
Next
MsgBox("Done")
End Sub
我正在使用 Visual Studio Community 2019。这些是该项目的参考资料:
如何使用另存为方法成功声明文件格式?
这称为 Enumeration
- 您可以通过向项目添加 PowerPoint 引用来包含它们,或者如果您使用的是后期绑定,则可以将其替换为它代表的数字(在本例中,数字 11),或创建您自己的自定义 Enumeration
.
这是 link 到 Enumeration
- ppSaveAsType Enumeration
我在使用 .NET Framework 4.7.2 的 Visual Basic 代码时遇到问题 运行。我正在使用 VBA for Office(文档)并尝试创建 PowerPoint 自动化工具。现在我遇到了 运行 问题,当我使用 SaveAs method for PowerPoint, the constant 时,我为参数 文件格式 提供的参数是 'not declared'。我相信我已经正确设置了所有引用。此外,SaveAs 方法通常有效,除非我尝试指定 文件格式 ,它会抛出此错误:
代码:
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
For Each sSourceFile As String In sFileLocations
Dim pptApp = CreateObject("PowerPoint.Application")
pptApp.visible = True
Dim sSourcePath = Mid(sSourceFile, 1, InStrRev(sSourceFile, "\"))
Dim sDestPattern = Mid(sSourceFile, InStrRev(sSourceFile, "\") + 1)
Dim sDestinationFile = Replace(sDestPattern, ".pptx", "", 1, -1, CompareMethod.Text)
sDestinationFile = Replace(sDestinationFile, ".ppt", "", 1, -1, CompareMethod.Text)
Dim pptPres = pptApp.Presentations.Open(sSourceFile)
' Debug.WriteLine(sSourcePath)
' Debug.WriteLine(sDestinationFile)
pptPres.SaveAs(sSourcePath & sDestinationFile & ".pptx", ppSaveAsDefault)
' Update PowerPoint thubmnail by adding new slide to the front then saving file
Dim pptLayout = pptPres.Slides(1).CustomLayout
Dim newSlide = pptPres.Slides.AddSlide(1, pptLayout)
pptPres.save()
' Remove new slide and save again to display correct thumbnail
Dim removeSlide = pptPres.Slides(1).Delete
pptPres.save()
pptPres.close()
pptApp.quit()
pptPres = Nothing
pptApp = Nothing
Next
MsgBox("Done")
End Sub
我正在使用 Visual Studio Community 2019。这些是该项目的参考资料:
如何使用另存为方法成功声明文件格式?
这称为 Enumeration
- 您可以通过向项目添加 PowerPoint 引用来包含它们,或者如果您使用的是后期绑定,则可以将其替换为它代表的数字(在本例中,数字 11),或创建您自己的自定义 Enumeration
.
这是 link 到 Enumeration
- ppSaveAsType Enumeration