vba - VBA PowerPoint 将变量设置为空
问题描述
我对以下代码有疑问。代码现在可以工作,但直到我将变量设置为空(请参阅代码中带有 *** 的部分)。我收到各种错误消息(例如“462 远程服务器机器不存在或不可用”)
我的问题是:为什么我必须将这些变量设置为空?我想这与我使用循环有关吗?
提前致谢!
Sub Saveas_PDF()
Dim PP As PowerPoint.Presentation
Dim prs As PowerPoint.Presentation
Dim Sl As PowerPoint.Slide
Dim sh As Variant
Dim company As String
Set Dropdown.ws_company = Tabelle2
company = Dropdown.ws_company.Range("C2").Value
Dim strPOTX As String
Dim strPfad As String
Dim pptApp As Object
Call filepicker
Dim Cell As Range
For Each Cell In Dropdown.ws_company.Range(Dropdown.ws_company.Cells(5, 3),
Dropdown.ws_company.Cells(Rows.Count,
3).End(xlUp)).SpecialCells(xlCellTypeVisible)
Dropdown.ws_company.Range("C2") = Cell
Set pptApp = New PowerPoint.Application
Dim pptVorlage As String
pptVorlage = myfilename
Set PP = pptApp.Presentations.Open(pptVorlage)
PP.UpdateLinks 'Datei --> Informationen --> Verknüpfungen --> Automatisch
aktualisieren Haken setzen
Dim newpath As String
newpath = Replace(myfilename, "AXO", "" & Cell & " AXO")
Dim newpathpdf As String
newpathpdf = Replace(newpath, "pptx", "pdf")
PP.ExportAsFixedFormat "" & newpathpdf & "", ppFixedFormatTypePDF,
ppFixedFormatIntentPrint
pptApp.Visible = True
Debug.Print (PP.Name)
AppActivate (PP.Name)
PP.Close
***Set pptApp = Nothing
Set PP = Nothing***
Next
Set pptApp = New PowerPoint.Application
If IsAppRunning("PowerPoint.Application") Then
If pptApp.Windows.Count = 0 Then
pptApp.Quit
End If
End If
End Sub
解决方案
可能是因为您在以下行中的 de 循环内调用构造函数“New”: Set pptApp = New PowerPoint.Application
在 de foreach 之前移动“Set pptApp = New PowerPoint.Application”行并尝试一下。
推荐阅读
- json - Hive table with nested JSON as string value
- ios - 更新@State后未调用SwiftUI UIViewControllerRepresentable.updateUIViewController
- c - What is difference between using function name and nickname(made from typedef) when declare another function?
- wpf - Groupbox适合可用空间WPF c#
- c# - 将此数据库中的文件转换为文本
- c# - Issue in editing field in ASP.NET CORE 2.2
- google-analytics - 将过去的交易数据添加到 GA
- angular - Angular8 - 如何使用 InjectionToken 和 ComponentPortal 将输入传递给 CDK Overlay
- php - 优化 MySQL:为什么我在 phpMyAdmin(当前进程)中看到 Command SLEEP?
- c# - 如何使用 Image Resizer Watermark Plugin 将水印对齐到右上角?