Hi,
I am trying to open xlsm (Excel macro enabled workbook) as a child window to windows forms in VB.NET using below code.
The xlsm is getting opened as a child to Forms, however on running macros, all options(Eg: File, Home ,insert) are greyed out in xlsm.
Code:
Imports System.Runtime.InteropServices
Imports Excel = Microsoft.Office.Interop.Excel
Public Class Form2
Public hwnd1 As IntPtr
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim excApp As New Excel.Application()
excApp.Visible = True
Dim wb As Excel.Workbook = excApp.Workbooks.Open("C:\xxyy\SampleMacro.xlsm", [ReadOnly]:=False)
hwnd1 = CType(excApp.Hwnd, IntPtr)
SetParent(hwnd1, Me.Handle)
MoveWindow(hwnd1, 0, 0, Me.Width, Me.Height, True)
End Sub
<DllImport("user32.dll")>
Public Shared Function SetParent(hWndChild As IntPtr, hWndNewParent As IntPtr) As IntPtr
End Function
<DllImport("user32.dll")>
Public Shared Function MoveWindow(hwnd As IntPtr, x As Integer, y As Integer, nWidth As Integer, nheight As Integer, repaint As Boolean) As Boolean
End Function
End Class
Environment:
OS Name: Microsoft Windows 10 Enterprise
OS Version: 10.0.15063 N/A Build 15063
System Type: x64-based PC
Excel version :Microsoft excel for office 365 MSO (16.0.12527.21230) 32-bit
Tried with various Excel-->Trust center-->trust center settings -->Macro settings, same behavior.
Microsoft.Office.Interop.Excel - version: 1.9.0.0
.Net framework 4.8
Attached the output of the program that I am getting now using the specified code.
Please help in getting xlsm opening in Read- Write mode after running a macro.