0
我有下面的代碼在VB.NET通過快遞2013 PowerPoint文件運行宏:使用vb.net打開簡報,保持打開狀態,以及在powerpoint關閉時如何釋放對象?
'Start PowerPoint and open the presentation.
Dim oPP = New Microsoft.Office.Interop.PowerPoint.Application()
oPP.Visible = MsoTriState.msoTrue
Dim oPresSet = oPP.Presentations
Dim oPres = oPresSet.Open(PFile)
oPP.Run("'Plan.ppt'!UpdatePlan")
oPres = Nothing
If Not oPresSet Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComObject(oPresSet)
oPresSet = Nothing
End If
oPP.Quit()
If Not oPP Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComObject(oPP)
oPP = Nothing
End If
我離開PowerPoint中打開,查看,然後通過PowerPoint中關閉該文件。當這個代碼重新運行代碼,我碰到下面的錯誤與下面的代碼行:
Dim oPP = New Microsoft.Office.Interop.PowerPoint.Application()
錯誤消息 - 「類型的未處理的異常‘System.Runtime.InteropServices.COMException’發生較高預算。 exe
其他信息:從IClassFactory創建CLSID爲{91493441-5A91-11CF-8700-00AA0060263B}的COM組件的實例因以下錯誤而失敗:800706b5。「
當通過powerpoint關閉PowerPoint文件時,是否有任何方法可以釋放對象,以便我可以無誤地重新運行代碼?
有沒有另外一種方法來做到這一點,以免我得到這些錯誤?
一直在這工作了很久,幫助將不勝感激。謝謝。
您是否試過'設置oPP =新Microsoft.Office.Interop.PowerPoint.Application()'而不是'Dim'然後'設置oPP = Nothing' – SSpoke
http://stackoverflow.com/questions/3197263/application- quit-method-failing-to-clear-process – SSpoke
剛剛嘗試過,但是當我使用Set關鍵字時,VB.Net 2013會擺脫它? – drraman