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

Hi,

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
Tina_BholeAsked:
Who is Participating?
 
CodeCruiserConnect With a Mentor Commented:
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")
        proc.WaitForInputIdle()
        SetParent(proc.MainWindowHandle, Me.Panel1.Handle)
        SendMessage(proc.MainWindowHandle, WM_SYSCOMMAND, SC_MAXIMIZE, 0)

    End Sub
End Class

Open in new window


scr
0
 
RinilCommented:
hi,

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

http://www.daniweb.com/software-development/vbnet/threads/332821/run-excel-macros-with-vb.net#

For more detailed view, have a look in below

http://msdn.microsoft.com/en-us/library/office/ff194819.aspx

hope this helps
0
 
CodeCruiserCommented:
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
Tina_BholeAuthor Commented:
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
0
 
Tina_BholeAuthor Commented:
Thanks heaps CodeCruiser. Thats exactly what I was looking for.
0
 
Éric MoreauSenior .Net ConsultantCommented:
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!
0
 
Éric MoreauSenior .Net ConsultantCommented:
I am now able to host Excel into a form but now the menus are not visible!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.