custom toolbars
custom toolbars
custom toolbars
custom toolbars
custom toolbars
custom toolbars custom toolbars custom toolbars custom toolbars custom toolbars custom toolbars custom toolbars custom toolbars
custom toolbars custom toolbars
custom toolbars
Go Back  Xtreme Visual Basic Talk > > > custom toolbars


Reply
 
Thread Tools Display Modes
  #1  
Old 02-03-2004, 02:31 PM
joek joek is offline
Freshman
 
Join Date: Sep 2003
Location: Tucson, AZ
Posts: 40
Default custom toolbars


Can we create custom excel toolbars with VB.Net?
If so, could you show me some sample code?

Thanks,
Joe K
Reply With Quote
  #2  
Old 02-03-2004, 03:07 PM
Mike Rosenblum's Avatar
Mike Rosenblum Mike Rosenblum is offline
Microsoft Excel MVP

Forum Leader
* Guru *
 
Join Date: Jul 2003
Location: New York, NY, USA
Posts: 7,848
Default

Joe, not to dissuade you, but well, maybe a little.... Developing a VBA solution in VB.Net is gunna get hairy.

If you need to have a custom interface w/in Excel, then I would seriously consider using VBA code residing within Excel itself, rather than trying to Automate Excel from VB.Net. Or using VB 6.0 would be orders of magnitude easier...

The problem is that using Automation through .Net's 'COM Interop' gets pretty hairy fast... You could read my tutorial on the subject to get some idea of what's involved:VB.Net Office Integration Tutorial or this thread is on-point as well VB.Net MaggieMay Thread

Once you understand this .Net Automation pretty well, you could read up here to learn about how to use the Office.CommandBars Object Model: Manipulating Command Bars and Command Bar Controls with VBA Code In particular, check out the code here: Creating a Command Bar

But keep in mind that the code in those MSDN web pages must be adapted for use in VB.Net as outlined in the VB.Net Tutorial...

I'm sorry this isn't any easier... I really would advise using VBA within Excel or even VB 6.0 if either of these are feasible for you.

,
Mike
__________________
My Articles:
| Excel from .NET | Excel RibbonX using VBA | Excel from VB6 | CVErr in .NET | MVP |
Avatar by Lebb
Reply With Quote
  #3  
Old 02-03-2004, 03:23 PM
joek joek is offline
Freshman
 
Join Date: Sep 2003
Location: Tucson, AZ
Posts: 40
Default

Thanks Mike,
You just saved me a lot of work. I currently have an excel application with inbedded VBA macros. It works great. But toolbars are a problem. Especially when trying to port from one version of Windows and Excel to another. Somehow the toolbars always get hosed. So I thought separating the VB from Excel would solve the portability problem. And it probably would. But I don't want the app. to go any slower and I don't
need any added complexity.

Thanks again,
Joe
Reply With Quote
  #4  
Old 02-03-2004, 03:46 PM
Mike Rosenblum's Avatar
Mike Rosenblum Mike Rosenblum is offline
Microsoft Excel MVP

Forum Leader
* Guru *
 
Join Date: Jul 2003
Location: New York, NY, USA
Posts: 7,848
Default

Ok, cool... yeah, to be honest, I am not personally prepared to develop anything VBA-oriented with VB.Net. It will take another generation for them to either get the 'COM Interop' to really work right, or go the other way: bringing VBA to the .Net platform. Either way, something has to change (or I'm not moving!).

As for your Toolbar Issues, if you post your Q in the Excel VBA Forum, I'm sure that you'll get lots of useful ideas and advice...

,
Mike
__________________
My Articles:
| Excel from .NET | Excel RibbonX using VBA | Excel from VB6 | CVErr in .NET | MVP |
Avatar by Lebb
Reply With Quote
  #5  
Old 02-15-2004, 04:45 PM
lichuk lichuk is offline
Newcomer
 
Join Date: Feb 2004
Location: UK
Posts: 8
Default

Quote:
Originally Posted by joek
Can we create custom excel toolbars with VB.Net?
If so, could you show me some sample code?

Thanks,
Joe K



Hi - Here is some code I wrote to create menus in a VB.Net App.

If you have Visual Studio.NET since there is a 'wizard' which sets up Com.Interop for you.


Code:
' defined somewhere in your Connect class you will need Dim WithEvents cbMenuItem As CommandBarButton ' defined somewhere in (or called by) OnStartUpCompete you need : Dim cbcMainMenu As CommandBarControl Dim cbcSubMenu As CommandBarControl ' create main menu item cbcMainMenu = applicationObject.CommandBars("Worksheet Menu Bar").Controls.Add(Type:=MsoControlType.msoControlPopup) cbcMainMenu.Caption = "New Menu" cbcMainMenu.Tag = "YourAppName" cbcMainMenu.Visible = True ' add a Sub Menu CreateSubMenu(cbcSubMenu, cbcMainMenu, "Any Old SubMenu Tag") ' add Sub Menu Item CreateMenuItem(cbMenuItem, cbcSubMenu, "Some Function or Other") ' add as many sub menus as you need along with a handler for each item ' These are some functions I created to add sub-menus and items. Private Function CreateMenuItem(ByRef cbTarget As CommandBarButton, ByVal cbcParant As CommandBarControl, ByVal strCaption As String) cbTarget = cbcParant.Controls.Add(Type:=MsoControlType.msoControlButton) cbTarget.Visible = True cbTarget.Style = MsoButtonStyle.msoButtonCaption cbTarget.Caption = strCaption cbTarget.OnAction = "!<YourAppName.Connect>" End Function Private Function CreateSubMenu(ByRef cbcTarget As CommandBarControl, ByRef cbcParant As CommandBarControl, ByVal strCaption As String) cbcTarget = cbcParant.Controls.Add(Type:=MsoControlType.msoControlPopup) cbcTarget.Visible = True cbcTarget.Caption = strCaption End Function ' here is the handler for the item created above Private Sub cbMenuItem_Click(ByVal Ctrl As Microsoft.Office.Core.CommandBarButton, ByRef CancelDefault As Boolean) Handles cbMenuItem.Click Try MsgBox("Doing Some Stuff") Catch ex As Exception MsgBox("Error! " & ex.ToString) End Try End Sub ' you also want to delete the top menu when OnBeginShutdown is called ' I call this code to achive it : Private Function DeleteMenu() On Error resume next Dim cbcMainMenu As CommandBarControl cbcMainMenu = applicationObject.CommandBars("Worksheet Menu Bar").FindControl(Tag:="YourAppName") If Not cbcMainMenu Is Nothing Then cbcMainMenu.Delete() End If cbcMainMenu = Nothing End Function

I did find the documentation from Microsft on the topic of .net Add-ins quite hard to get working at first - but once you get it working, it's really powerful and fast, and you get access to all of the .NET features.

Personally, I prefer it to writing add-ins the hard way (in C++)


Cheers

lich uk
Reply With Quote
  #6  
Old 02-15-2004, 04:54 PM
Mike Rosenblum's Avatar
Mike Rosenblum Mike Rosenblum is offline
Microsoft Excel MVP

Forum Leader
* Guru *
 
Join Date: Jul 2003
Location: New York, NY, USA
Posts: 7,848
Default

Have you had problems "hanging" your applications? This seems to be a major theme (unfortunately) in usingn COM Interop in .Net...

What's been your experience?

-- Mike
__________________
My Articles:
| Excel from .NET | Excel RibbonX using VBA | Excel from VB6 | CVErr in .NET | MVP |
Avatar by Lebb
Reply With Quote
  #7  
Old 02-15-2004, 05:02 PM
lichuk lichuk is offline
Newcomer
 
Join Date: Feb 2004
Location: UK
Posts: 8
Default

No problems with hanging.

The only problems I've had so far were when I accidentally packaged a wrong DLL version which caused some weirdness when using timers.

But then again, I've not been pushing the envelope.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PlaySound and Custom Resource .wav Magic API 6 08-30-2003 07:17 PM
Unhiding Toolbars when switching spreadsheets MDodd73 Excel 1 07-06-2003 12:08 PM
Fine Tuning Toolbars MDodd73 Excel 1 07-02-2003 09:03 AM
Transferring custom lists and toolbars between users Lannock General 0 02-26-2003 02:46 AM
Word VBA: Getting rid of all Word Toolbars... simonsays Word, PowerPoint, Outlook, and Other Office Products 1 06-14-2002 12:14 AM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
custom toolbars
custom toolbars
custom toolbars custom toolbars
custom toolbars
custom toolbars
custom toolbars custom toolbars custom toolbars custom toolbars custom toolbars custom toolbars custom toolbars
custom toolbars
custom toolbars
 
custom toolbars
custom toolbars
 
-->