Embedding Excel (Macro enabled) file in windows form in

Posted on 2012-08-19
Last Modified: 2013-01-06

I have a macro enabled Excel file, saved on my c drive as mytemp.xltm

My question is, how do I open the file in windows form in at run time?
Or is there a way to add this excel template to windows form at design time?

So, basically, I am looking at embedding this file into form in read/write mode.

Thanks in advance
Question by:Tina_Bhole
    LVL 5

    Expert Comment


    Below link may help with a sample example showing how to open a excel in

    For more detailed view, have a look in below

    hope this helps
    LVL 83

    Expert Comment


    Author Comment

    Hi all,

    Thanks for replying.
    But unfortunately, none of these is helping me with what I want to acheive. I actually want to open excel work sheet in read and write mode within the application, not seperately.
    Codecruiser, I tried your code but could not figure out how to make it work with excel. For some reason it kept on opening browser in a new window but could not recognise excel as an applicaiton process
    LVL 83

    Accepted Solution

    I tested following code and you can see the result

    Imports System.Runtime.InteropServices
    Public Class Form1
        Private Const WM_SYSCOMMAND As Integer = 274
        Private Const SC_MAXIMIZE As Integer = 61488
        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 Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            'Run Notepad application inside Panel1 control
            Dim proc As Process
            proc = Process.Start("Notepad.exe")
            SetParent(proc.MainWindowHandle, Me.Panel1.Handle)
            SendMessage(proc.MainWindowHandle, WM_SYSCOMMAND, SC_MAXIMIZE, 0)
        End Sub
    End Class

    Open in new window


    Author Comment

    Thanks heaps CodeCruiser. Thats exactly what I was looking for.
    LVL 69

    Expert Comment

    by:Éric Moreau
    you have been able to do it with Excel?

    On my machine (Windows 8, Office 2013), Notepad opens correctly inside the panel but Excel opens a standalone instance!
    LVL 69

    Expert Comment

    by:Éric Moreau
    I am now able to host Excel into a form but now the menus are not visible!

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
    Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
    This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
    This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now