首页 > 解决方案 > Run PowerPoint with the exe macro file

问题描述

My development environment is Windows 8 64Bit & 10 64Bit, and Visual Studio is 2013.

The VBA file I wrote looks like this:

// source start !!!

Imports PowerPoint = Microsoft.Office.Interop.PowerPoint

Module Module1

Sub Main(ByVal path() As String)

    Dim oApplication As PowerPoint.Application = Nothing

    Dim oPressentation As PowerPoint.Presentation = Nothing

    Try

        oApplication = New Microsoft.Office.Interop.PowerPoint.Application()

        oPressentation = oApplication.Presentations.Add

        Dim macroPath As String = path(0)

        Dim savePath As String = path(1)

        oPressentation.VBProject.VBComponents.Import(macroPath)

        oApplication.Run("ExportPowerPoint")

        oPressentation.SaveAs(savePath)

    Catch ex As Exception

    Finally

        If Not oPressentation Is Nothing Then

            oPressentation = Nothing

        End If

        If Not oApplication Is Nothing Then

            oApplication = Nothing

        End If

        GC.Collect()

        GC.WaitForPendingFinalizers()

    End Try

End Sub

End Module

// source end !!!

When the function is executed, it executes the power point and executes the macro.

However, if the power point is executed before executing the function, the function does not work properly when the exe file is executed. The same power point just turns on and ends.

In addition, after executing the function, even if you run the power point on the desktop.

标签: vb.net

解决方案


推荐阅读