hophead3 Posted April 20, 2006 Posted April 20, 2006 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! Quote
Mike_R Posted April 21, 2006 Posted April 21, 2006 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 Quote Posting Guidelines Avatar by Lebb
hophead3 Posted April 21, 2006 Author Posted April 21, 2006 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. Quote
Mike_R Posted April 22, 2006 Posted April 22, 2006 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 Quote Posting Guidelines Avatar by Lebb
Recommended Posts