Embedding Excel (Macro enabled) file in windows form in VB.net

Posted on 2012-08-19
Medium Priority
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 vb.net 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 vb.net form in read/write mode.

Thanks in advance
Question by:Tina_Bhole
  • 2
  • 2
  • 2
  • +1

Expert Comment

ID: 38310801

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


For more detailed view, have a look in below


hope this helps
LVL 83

Expert Comment

ID: 38311064

Author Comment

ID: 38314447
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 83

Accepted Solution

CodeCruiser earned 1600 total points
ID: 38328462
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

ID: 38335031
Thanks heaps CodeCruiser. Thats exactly what I was looking for.
LVL 70

Expert Comment

by:Éric Moreau
ID: 38748490
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 70

Expert Comment

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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

850 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