Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi, I'm 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 ? I've 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 I've read, the CommandBars statement should enable this menu, but it doesn't. What am I missing?

 

Thanks!

Posted

It looks like you have the critical line commented out!

 

That said, I would try this:

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, there's a tutorial here which covers some of the basics that you might find useful.)

 

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

 

:),

Mike

Posting Guidelines

 

Avatar by Lebb

Posted
Mike, thanks for the reply. Actually, it's the .visible line that got it to work for me. The CommandBars line isn't needed. I happened to run across it on Microsoft's support site just before getting your reply (I think it was KB Article ID: 303017 that used the .visible line). Thanks again.
Posted

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

Posting Guidelines

 

Avatar by Lebb

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...