使用宏内部窗体显示Excel工作表

时间:2017-06-07 19:16:40

标签: excel vba excel-vba

我在.net中得到了应用程序,我想在我的表单中显示带有宏的excel表。我发现代码在面板中显示excel文件,一切正常但是一旦我运行宏它冻结了。如果我不会运行宏它的工作正常。

Imports excel = Microsoft.office.interop.excel
Imports office = Microsoft.office.core



Public Class Form1
   Declare Auto Function SetParent Lib "user32.dll" (ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As Integer
    Declare Auto Function SendMessage Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
    Private Const WM_SYSCOMMAND As Integer = 274
    Private Const SC_MAXIMIZE As Integer = 61488
    Private Sub btnShowExcel_Click(sender As Object, e As EventArgs) Handles btnShowExcel.Click
        Dim sExcelFileName = "D:\123.xlsm"
        Dim oExcel As New Excel.Application
        oExcel.DisplayAlerts = False
        oExcel.Workbooks.Open(sExcelFileName)
        oExcel.Application.WindowState = excel.XlWindowState.xlNormal
        oExcel.Visible = True
        SetParent(oExcel.Hwnd, pnlExcel.Handle)
        SendMessage(oExcel.Hwnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0)
    End Sub


End Class

任何人都可以帮我改变这段代码或找到不同的代码,这样我就能用宏显示excel文件,宏也可以正常工作。

由于 问候 标记

0 个答案:

没有答案