Create Excel App in VB.NET

hophead3

New member
Joined
Apr 20, 2006
Messages
2
Hi, Im creating an Excel application and adding a new worksheet to it in a VB.NET windows application. The problem is, I want to be able to print the worksheet or save it. When I create the instance of the Excel application, the normal (File, Edit, View...etc) menu is not there at the top of the window. How can I get this to appear ? Ive tried something like this:

mAppExcel = New Excel.Application
mWrkExcel = mAppExcel.Workbooks.Add
mWrkExcel.Application.WindowState = Excel.XlWindowState.xlNormal
mAppExcel.CommandBars("Worksheet Menu Bar").Enabled = True

From what Ive read, the CommandBars statement should enable this menu, but it doesnt. What am I missing?

Thanks!
 
It looks like you have the critical line commented out!

That said, I would try this:
Code:
mAppExcel = New Excel.Application
mAppExcel.Visible = True
mAppExcel.WindowState = Excel.XlWindowState.xlNormal
mWrkExcel = mAppExcel.Workbooks.Add
AppExcel.CommandBars(1).Enabled = True
Note that the above indexes the CommandBars(1) instead of CommandBars("Worksheet Menu Bar"). This is simply because using 1 is language independent, while using "Worksheet Menu Bar" would only work for english-language versions of Excel.

(Also, theres a tutorial here which covers some of the basics that you might find useful.)

Anyway, the above should work, give it a try...

:),
Mike
 
Mike, thanks for the reply. Actually, its the .visible line that got it to work for me. The CommandBars line isnt needed. I happened to run across it on Microsofts support site just before getting your reply (I think it was KB Article ID: 303017 that used the .visible line). Thanks again.
 
Ok, cool...

Yes, Excel defaults to .Visible = False unless you tell it otherwise.

Strange, though, Excel should not have been visible AT ALL without this line, and you only mentioned an issue with the CommandBars?

Anyway, glad you got it!
:),
Mike
 
Back
Top