我在我的VB.NET应用程序中使用Imports语句实现PowerPoint自动化:
Imports PowerPoint = Microsoft.Office.Interop.PowerPoint当然,我必须检查用户的机器上是否安装了PowerPoint。但是,由于此引用,应用程序不会启动或加载,从而使我有机会检查PowerPoint是否已安装。下面是我用来签入表单加载的代码
Dim officeType As Type = Type.GetTypeFromProgID("PowerPoint.Application")
If officeType Is Nothing Then
MessageBox.Show("PPT is not installed")
Else
MessageBox.Show("PPT is installed")
End If有什么建议可以解决这个问题吗?
发布于 2020-05-21 03:46:12
基于Jimi和TbTinMn的评论,我解决了这个问题。我将Imports语句替换为Dim powerPointType并重新创建了应用程序实例,如下所示:在公共类Form1下,添加
'// PowerPoint automation
Dim PowerPointType = Type.GetTypeFromProgID("PowerPoint.Application")
Dim PowerPoint = Activator.CreateInstance(PowerPointType)
Dim oApp As New Microsoft.Office.Interop.PowerPoint.Application
Dim oPres As Microsoft.Office.Interop.PowerPoint.Presentation
Dim oSlide As PowerPoint.Slide然后,您可以使用PPT应用程序完成代码,例如,导出或另存为
'// open MS PowerPoint with hidden window
oPres = oApp.Presentations.Open(ppt_filename, , , Microsoft.Office.Core.MsoTriState.msoFalse)https://stackoverflow.com/questions/61905735
复制相似问题