View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Paul Reynolds[_2_] Paul Reynolds[_2_] is offline
external usenet poster
 
Posts: 8
Default Opening Excel in my program

Sort of...

In VB.NET you can use code like:

Public Sub SomeSub(...)
Dim xlApp as Excel.Application

Set xlApp = New Excel.Application
' your VBA code here
xlApp.Quit
End Sub

and then compile this into an .exe. You will need to set a reference to the
Excel library (on the COM tab) in your code, and every top-level call to
Excel will need to be qualified using xlApp (e.g. if your VBA used the
Workbooks collection, this would need to be changed to xlApp.Workbooks).

This still opens Excel, and so still requires the end-user to have Excel
installed on their machine, however, Excel will not be visible to the
end-user.

Note that there are some small differences between VBA and VB.NET (e.g.
using End While instead of Wend), these are all documented in the Visual
Studio.NET documentation.

Let me know how you get on.

Cheers,
Paul

"tehwa" wrote in message
...
Paul,

I posted a pretty silly post 'here'
(http://www.excelforum.com/t177312-s) a few minutes ago about running a
macro from an .exe file. Can I write an application in VB.net that will
perform the same task as the macro, but perform it as an exe without
opening excel.

The macro simply formats an xls file so that it can be imported into a
database.

Thanks

tehwa


---
Message posted from http://www.ExcelForum.com/