3 Replies - 495 Views - Last Post: 01 May 2013 - 11:50 AM Rate Topic: -----

#1 njhokie  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 17-January 13

Add External Program (Excel or .exe) to Form Control

Posted 01 May 2013 - 06:33 AM

Is it possible/practical to display the contents of an external program on a windows form? Specifically I am looking to have an Excel workbook display on a form, such as inside a Panel control, while another part of the form will have controls to switch between various worksheets.

Any help in pointing me in the right direction would be helpful. I have all the Excel code in place to open the workbook, but I have not gotten beyond trying
 mypanel.Controls.Add((Control)myExcelWEorkbook); 
and having it crash.

Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: Add External Program (Excel or .exe) to Form Control

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3552
  • View blog
  • Posts: 11,008
  • Joined: 05-May 12

Re: Add External Program (Excel or .exe) to Form Control

Posted 01 May 2013 - 06:43 AM

What your looking to do is host Excel as an ActiveX object. It is doable, but the question really is: why?

If Excel is going to be the primary workspace for the user, would it make more sense to write something in VBA instead and do everything in Excel?

If all you need is to display simple data, there is the DataGridView control in WinForms that is amazingly good for presenting grid data and you can potentially have your Excel file as a data source.
Was This Post Helpful? 1
  • +
  • -

#3 njhokie  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 17-January 13

Re: Add External Program (Excel or .exe) to Form Control

Posted 01 May 2013 - 07:49 AM

Thanks for the reply.

I do have a lot of VBA code on the Excel worksheet already, but found that making a gui using what is available to Excel was not very elegant. So I just want to take advantage of some of the C# elements, e.g. treeview, to help guide the user through the workbook. This would prevent from having to port the VBA code over to C#.
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3360
  • View blog
  • Posts: 11,382
  • Joined: 12-December 12

Re: Add External Program (Excel or .exe) to Form Control

Posted 01 May 2013 - 11:50 AM

A TreeView control, and many others, are available to Excel UserForms. Right-click the toolbox in Excel VBA and choose Additional Controls. However, you would need to do some searching to find its documentation. You would also need to ensure that this control will be available if you distribute your application.

I am not necessarily trying to put you off of using C#, but if you only need a couple of controls then this might be worth investigating. You should also consider that a .NET application will not achieve the performance of a (native) Excel VBA Application.

In Excel VBA you can also make use of Open and Save, etc., dialogs.

msoFileDialogFilePicker
msoFileDialogFolderPicker
msoFileDialogOpen
msoFileDialogSaveAs

http://www.wiseowl.c...-filedialog.htm

This post has been edited by andrewsw: 01 May 2013 - 11:53 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1