Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Updating Custom Menu Code References when New Workbook is saved

Hi.

I'm using custom menu items to load and display forms in an Excel 2000
workbook, Application v1.0 If I save the workbook as Application v2.0 and
click on a menu item to load a form, Excel goes and finds Application v1.0.
How do I programmatically remove these links, so that Application v2.0 will
use the code directly behind that workbook?


TIA,

Jim
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Updating Custom Menu Code References when New Workbook is saved

Are the menus manually built and assigned to macros?

If so, try creating them dynamically in Workbook_Open.

Simple example


Private Sub Workbook_Open()
Dim oCb As CommandBar
Dim oCtl As CommandBarPopup
Dim oCtlBtn As CommandBarButton

Set oCb = Application.CommandBars("Worksheet Menu Bar")
With oCb
Set oCtl = .Controls("Tools").Controls.Add( _
Type:=msoControlPopup, _
temporary:=True)
oCtl.Caption = "myButton"
With oCtl
Set oCtlBtn = .Controls.Add( _
Type:=msoControlButton, _
temporary:=True)
oCtlBtn.Caption = "myMacroButton"
oCtlBtn.FaceId = 161
oCtlBtn.OnAction = "myMacro"
End With
With oCtl
Set oCtlBtn = .Controls.Add( _
Type:=msoControlButton, _
temporary:=True)
oCtlBtn.Caption = "myMacroButton2"
oCtlBtn.FaceId = 161
oCtlBtn.OnAction = "myMacro2"
End With
'etc.
End With
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim oCb As CommandBar

Set oCb = Application.CommandBars("Worksheet Menu Bar")
oCb.Controls("Tools").Controls("myButton").Delete
End Sub


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"JimRWR" wrote in message
...
Hi.

I'm using custom menu items to load and display forms in an Excel 2000
workbook, Application v1.0 If I save the workbook as Application v2.0 and
click on a menu item to load a form, Excel goes and finds Application
v1.0.
How do I programmatically remove these links, so that Application v2.0
will
use the code directly behind that workbook?


TIA,

Jim



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Updating Custom Menu Code References when New Workbook is saved

Thanks, Bob, that works. One other question - what property is available for
custom drop down menus? I tried manipulating the type property of the
CommandBarControl object to msoControlButtonDropDown, but get the Invalid
Procedure Call Argument (RTE 5) error.

Jim

"JimRWR" wrote:

Hi.

I'm using custom menu items to load and display forms in an Excel 2000
workbook, Application v1.0 If I save the workbook as Application v2.0 and
click on a menu item to load a form, Excel goes and finds Application v1.0.
How do I programmatically remove these links, so that Application v2.0 will
use the code directly behind that workbook?


TIA,

Jim

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Updating Custom Menu Code References when New Workbook is saved

It is not a button so you can't use button.

Here is some example code, not the variable type has been changed for this

Dim oCb As CommandBar
Dim oCtl As CommandBarPopup
Dim oCtlBtn As CommandBarControl

Set oCb = Application.CommandBars("Worksheet Menu Bar")
With oCb
Set oCtl = .Controls("Tools").Controls.Add( _
Type:=msoControlPopup, _
temporary:=True)
oCtl.Caption = "myButton"
With oCtl
Set oCtlBtn = .Controls.Add( _
Type:=msoControlDropdown, _
temporary:=True)
oCtlBtn.Caption = "myMacroButton"
oCtlBtn.OnAction = "myMacro"
oCtlBtn.AddItem "Bob"
oCtlBtn.AddItem "Lynne"
oCtlBtn.AddItem "Amy"
oCtlBtn.AddItem "Hannah"
oCtlBtn.AddItem "Brian"
End With
End With

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"JimRWR" wrote in message
...
Thanks, Bob, that works. One other question - what property is available
for
custom drop down menus? I tried manipulating the type property of the
CommandBarControl object to msoControlButtonDropDown, but get the Invalid
Procedure Call Argument (RTE 5) error.

Jim

"JimRWR" wrote:

Hi.

I'm using custom menu items to load and display forms in an Excel 2000
workbook, Application v1.0 If I save the workbook as Application v2.0
and
click on a menu item to load a form, Excel goes and finds Application
v1.0.
How do I programmatically remove these links, so that Application v2.0
will
use the code directly behind that workbook?


TIA,

Jim



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Code snippets for custom menu Bob Excel Programming 2 July 18th 07 01:48 AM
Updating Ranges or References in Code when Adding or Deleting Rows Arnold[_3_] Excel Programming 1 February 6th 07 01:23 PM
custom menu bar mispelled, where is the code for it? No Name Excel Programming 0 March 21st 06 04:53 PM
Extracting Custom Menu Code windsurferLA Excel Programming 2 February 5th 05 07:29 PM
Deleting custom Commands from File Menu are nor saved next time w. EXCEL CUstomization Excel Worksheet Functions 3 December 7th 04 01:46 AM


All times are GMT +1. The time now is 08:15 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"