Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Menu Bar Problems

Time to switch Commandbars

Sub AddMenu2()
Dim FileMenu
With Application.CommandBars("Worksheet Menu Bar")
On Error Resume Next
.Controls("Test").Delete
On Error GoTo 0
Dim i
' Find the File menu
Set FileMenu = CommandBars(1).FindControl(ID:=30002)
With .Controls.Add(Type:=msoControlPopup, befo=FileMenu.Index,
temporary:=True)
.Caption = "Test"
With .Controls.Add(Type:=msoControlButton, temporary:=True)
.Caption = "Test1"
.OnAction = "Main"
.Tag = 1
End With
With .Controls.Add(Type:=msoControlButton, temporary:=True)
.Caption = "Test2"
.OnAction = "Main"
.Tag = 2
End With
'(etc.)
End With
End With
End Sub


Sub Main()
Dim intTest As Integer
'Use intTest as a row lookup parameter _
and do something with it
intTest = Application.CommandBars.ActionControl.Tag
MsgBox intTest
End Sub



--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"TrevorJ" wrote in message
...
Hi,
I have developed an Excel application that uses quite an extensive menu
system to 'work' it. I have not been able to get my head round the 'new'
command bars syntax, so have used the stoneage MenuBars code.
What I am trying to do is pass a single Proc a parameter from multiple

menu
lines. I have not achieved this and have the following working code at
present.

Sub AddMenu2()
MenuBars(xlWorksheet).Menus.Add Caption:="Test", befo="File"
With MenuBars(xlWorksheet).Menus("Test").MenuItems
.Add Caption:="Test1", OnAction:="Test1"
.Add Caption:="Test2", OnAction:="Test2"
(etc.)
End With
End Sub

Sub Test1()
Call Main(1)
End Sub

Sub Test2()
Call Main(2)
End Sub
(Etc.)

Sub Main(intTest As Integer)
'Use intTest as a row lookup parameter _
and do something with it
End Sub

What I want to do is cut out the middle Procs (Test1, Test2 etc) and call
the 'Main' proc directly from the menu, passing it the integer parameter

at
the same time. Such as like this:-

.Add Caption:="Test1", OnAction:="Main(1)"
.Add Caption:="Test2", OnAction:="Main(2)"

Which obviously does not work.
I have done this before, but:-
a. Can't remember how, and experimenting leads to failure
b. I think that it seemed to call the 'Main' twice for some reason or
another.

TIA
Trevor






  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Menu Bar Problems

Take a look at http://www.j-walk.com/ss/excel/tips/tip53.htm

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"TrevorJ" wrote in message
...
Bob,
Thanks for the quick reply. I suppose that I will have to drag myself out

of
the stone age and recode my menu system. I'll giv it a try in a bit, once
that I have got my head round how I can build it from a 'table of

contents'
area on a worksheet.
Thanks again. I'll let you know how I got on.

Trevor

"Bob Phillips" wrote:

Time to switch Commandbars

Sub AddMenu2()
Dim FileMenu
With Application.CommandBars("Worksheet Menu Bar")
On Error Resume Next
.Controls("Test").Delete
On Error GoTo 0
Dim i
' Find the File menu
Set FileMenu = CommandBars(1).FindControl(ID:=30002)
With .Controls.Add(Type:=msoControlPopup,

befo=FileMenu.Index,
temporary:=True)
.Caption = "Test"
With .Controls.Add(Type:=msoControlButton, temporary:=True)
.Caption = "Test1"
.OnAction = "Main"
.Tag = 1
End With
With .Controls.Add(Type:=msoControlButton, temporary:=True)
.Caption = "Test2"
.OnAction = "Main"
.Tag = 2
End With
'(etc.)
End With
End With
End Sub


Sub Main()
Dim intTest As Integer
'Use intTest as a row lookup parameter _
and do something with it
intTest = Application.CommandBars.ActionControl.Tag
MsgBox intTest
End Sub



--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"TrevorJ" wrote in message
...
Hi,
I have developed an Excel application that uses quite an extensive

menu
system to 'work' it. I have not been able to get my head round the

'new'
command bars syntax, so have used the stoneage MenuBars code.
What I am trying to do is pass a single Proc a parameter from multiple

menu
lines. I have not achieved this and have the following working code at
present.

Sub AddMenu2()
MenuBars(xlWorksheet).Menus.Add Caption:="Test", befo="File"
With MenuBars(xlWorksheet).Menus("Test").MenuItems
.Add Caption:="Test1", OnAction:="Test1"
.Add Caption:="Test2", OnAction:="Test2"
(etc.)
End With
End Sub

Sub Test1()
Call Main(1)
End Sub

Sub Test2()
Call Main(2)
End Sub
(Etc.)

Sub Main(intTest As Integer)
'Use intTest as a row lookup parameter _
and do something with it
End Sub

What I want to do is cut out the middle Procs (Test1, Test2 etc) and

call
the 'Main' proc directly from the menu, passing it the integer

parameter
at
the same time. Such as like this:-

.Add Caption:="Test1", OnAction:="Main(1)"
.Add Caption:="Test2", OnAction:="Main(2)"

Which obviously does not work.
I have done this before, but:-
a. Can't remember how, and experimenting leads to failure
b. I think that it seemed to call the 'Main' twice for some reason or
another.

TIA
Trevor









  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,071
Default Menu Bar Problems

As far as learning to work with Commandbars goes, I would suggest you factor
in your plans for Office 2007. That product uses something different
altogether -- called the Ribbon in the UI and RibbonX on the developer side.
So, if you intend transitioning to 2007 in the near future you may be able
to skip learning about Commandbars altogether. ;-)

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article ,
says...
Bob,
Thanks for the quick reply. I suppose that I will have to drag myself out of
the stone age and recode my menu system. I'll giv it a try in a bit, once
that I have got my head round how I can build it from a 'table of contents'
area on a worksheet.
Thanks again. I'll let you know how I got on.

Trevor

"Bob Phillips" wrote:

Time to switch Commandbars

Sub AddMenu2()
Dim FileMenu
With Application.CommandBars("Worksheet Menu Bar")
On Error Resume Next
.Controls("Test").Delete
On Error GoTo 0
Dim i
' Find the File menu
Set FileMenu = CommandBars(1).FindControl(ID:=30002)
With .Controls.Add(Type:=msoControlPopup, befo=FileMenu.Index,
temporary:=True)
.Caption = "Test"
With .Controls.Add(Type:=msoControlButton, temporary:=True)
.Caption = "Test1"
.OnAction = "Main"
.Tag = 1
End With
With .Controls.Add(Type:=msoControlButton, temporary:=True)
.Caption = "Test2"
.OnAction = "Main"
.Tag = 2
End With
'(etc.)
End With
End With
End Sub


Sub Main()
Dim intTest As Integer
'Use intTest as a row lookup parameter _
and do something with it
intTest = Application.CommandBars.ActionControl.Tag
MsgBox intTest
End Sub



--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"TrevorJ" wrote in message
...
Hi,
I have developed an Excel application that uses quite an extensive menu
system to 'work' it. I have not been able to get my head round the 'new'
command bars syntax, so have used the stoneage MenuBars code.
What I am trying to do is pass a single Proc a parameter from multiple

menu
lines. I have not achieved this and have the following working code at
present.

Sub AddMenu2()
MenuBars(xlWorksheet).Menus.Add Caption:="Test", befo="File"
With MenuBars(xlWorksheet).Menus("Test").MenuItems
.Add Caption:="Test1", OnAction:="Test1"
.Add Caption:="Test2", OnAction:="Test2"
(etc.)
End With
End Sub

Sub Test1()
Call Main(1)
End Sub

Sub Test2()
Call Main(2)
End Sub
(Etc.)

Sub Main(intTest As Integer)
'Use intTest as a row lookup parameter _
and do something with it
End Sub

What I want to do is cut out the middle Procs (Test1, Test2 etc) and call
the 'Main' proc directly from the menu, passing it the integer parameter

at
the same time. Such as like this:-

.Add Caption:="Test1", OnAction:="Main(1)"
.Add Caption:="Test2", OnAction:="Main(2)"

Which obviously does not work.
I have done this before, but:-
a. Can't remember how, and experimenting leads to failure
b. I think that it seemed to call the 'Main' twice for some reason or
another.

TIA
Trevor








  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Menu Bar Problems

Tushar,
That's a good point.
However, the other option is to not make the transition.
I am still trying to decide.
Regards,
Jim Cone
San Francisco, USA


"Tushar Mehta"

wrote in message
As far as learning to work with Commandbars goes, I would suggest you factor
in your plans for Office 2007. That product uses something different
altogether -- called the Ribbon in the UI and RibbonX on the developer side.
So, if you intend transitioning to 2007 in the near future you may be able
to skip learning about Commandbars altogether. ;-)
--
Regards,
Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Menu Bar Problems

They are supported, but they don't appear as they do in say 2003. They get
installed in the Developer tab as buttons. And it's a darn sight easier to
create commandbars than playing with the ribbon.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"TrevorJ" wrote in message
...
Ok Ok, there's always a catch with the nice Mr. Gates' software isnt

there.
As menu bars are still supported in O 2003, is it reasonably safe to

assume
that command bars will be backwards compatible with O2k7?

Thanks to the Command bar help that I have had, I've solved my immidiate
problem, but O2k7?????

Trevor

"Tushar Mehta" wrote:

As far as learning to work with Commandbars goes, I would suggest you

factor
in your plans for Office 2007. That product uses something different
altogether -- called the Ribbon in the UI and RibbonX on the developer

side.
So, if you intend transitioning to 2007 in the near future you may be

able
to skip learning about Commandbars altogether. ;-)

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article ,
says...
Bob,
Thanks for the quick reply. I suppose that I will have to drag myself

out of
the stone age and recode my menu system. I'll giv it a try in a bit,

once
that I have got my head round how I can build it from a 'table of

contents'
area on a worksheet.
Thanks again. I'll let you know how I got on.

Trevor

"Bob Phillips" wrote:

Time to switch Commandbars

Sub AddMenu2()
Dim FileMenu
With Application.CommandBars("Worksheet Menu Bar")
On Error Resume Next
.Controls("Test").Delete
On Error GoTo 0
Dim i
' Find the File menu
Set FileMenu = CommandBars(1).FindControl(ID:=30002)
With .Controls.Add(Type:=msoControlPopup,

befo=FileMenu.Index,
temporary:=True)
.Caption = "Test"
With .Controls.Add(Type:=msoControlButton,

temporary:=True)
.Caption = "Test1"
.OnAction = "Main"
.Tag = 1
End With
With .Controls.Add(Type:=msoControlButton,

temporary:=True)
.Caption = "Test2"
.OnAction = "Main"
.Tag = 2
End With
'(etc.)
End With
End With
End Sub


Sub Main()
Dim intTest As Integer
'Use intTest as a row lookup parameter _
and do something with it
intTest = Application.CommandBars.ActionControl.Tag
MsgBox intTest
End Sub



--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"TrevorJ" wrote in message
...
Hi,
I have developed an Excel application that uses quite an extensive

menu
system to 'work' it. I have not been able to get my head round the

'new'
command bars syntax, so have used the stoneage MenuBars code.
What I am trying to do is pass a single Proc a parameter from

multiple
menu
lines. I have not achieved this and have the following working

code at
present.

Sub AddMenu2()
MenuBars(xlWorksheet).Menus.Add Caption:="Test", befo="File"
With MenuBars(xlWorksheet).Menus("Test").MenuItems
.Add Caption:="Test1", OnAction:="Test1"
.Add Caption:="Test2", OnAction:="Test2"
(etc.)
End With
End Sub

Sub Test1()
Call Main(1)
End Sub

Sub Test2()
Call Main(2)
End Sub
(Etc.)

Sub Main(intTest As Integer)
'Use intTest as a row lookup parameter _
and do something with it
End Sub

What I want to do is cut out the middle Procs (Test1, Test2 etc)

and call
the 'Main' proc directly from the menu, passing it the integer

parameter
at
the same time. Such as like this:-

.Add Caption:="Test1", OnAction:="Main(1)"
.Add Caption:="Test2", OnAction:="Main(2)"

Which obviously does not work.
I have done this before, but:-
a. Can't remember how, and experimenting leads to failure
b. I think that it seemed to call the 'Main' twice for some

reason or
another.

TIA
Trevor













  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Menu Bar Problems

Exactly Trevor. Many years ago I used it and added about 6 columns, tag,
parameter, a picture, etc. As I recall, adding extra columns wasn't as
simple as (I think) it should be, but it worked eventually. After a while,
it wasn't flexible enough for me (I wanted VBA menus as well, so I built my
own, but it did me well for a while.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"TrevorJ" wrote in message
...
Bob,
That link is realy good. It's more or less what I am doing at the moment,
but much better. Presumably I could add one more column to the table and
include a Tag value and modify the code slightly to include:-

Case 2 ' A Menu Item
If NextLevel = 3 Then
Set MenuItem =
MenuObject.Controls.Add(Type:=msoControlPopup)
Else
Set MenuItem =
MenuObject.Controls.Add(Type:=msoControlButton)
MenuItem.OnAction = PositionOrMacro
MenuItem.Tag = <value extracted from extra column
End If

to achieve a solution to my original problem?
I'll give it a go to see what happens.
Thanks again

Trevor

"Bob Phillips" wrote:

Take a look at http://www.j-walk.com/ss/excel/tips/tip53.htm

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"TrevorJ" wrote in message
...
Bob,
Thanks for the quick reply. I suppose that I will have to drag myself

out
of
the stone age and recode my menu system. I'll giv it a try in a bit,

once
that I have got my head round how I can build it from a 'table of

contents'
area on a worksheet.
Thanks again. I'll let you know how I got on.

Trevor

"Bob Phillips" wrote:

Time to switch Commandbars

Sub AddMenu2()
Dim FileMenu
With Application.CommandBars("Worksheet Menu Bar")
On Error Resume Next
.Controls("Test").Delete
On Error GoTo 0
Dim i
' Find the File menu
Set FileMenu = CommandBars(1).FindControl(ID:=30002)
With .Controls.Add(Type:=msoControlPopup,

befo=FileMenu.Index,
temporary:=True)
.Caption = "Test"
With .Controls.Add(Type:=msoControlButton,

temporary:=True)
.Caption = "Test1"
.OnAction = "Main"
.Tag = 1
End With
With .Controls.Add(Type:=msoControlButton,

temporary:=True)
.Caption = "Test2"
.OnAction = "Main"
.Tag = 2
End With
'(etc.)
End With
End With
End Sub


Sub Main()
Dim intTest As Integer
'Use intTest as a row lookup parameter _
and do something with it
intTest = Application.CommandBars.ActionControl.Tag
MsgBox intTest
End Sub



--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"TrevorJ" wrote in message
...
Hi,
I have developed an Excel application that uses quite an extensive

menu
system to 'work' it. I have not been able to get my head round the

'new'
command bars syntax, so have used the stoneage MenuBars code.
What I am trying to do is pass a single Proc a parameter from

multiple
menu
lines. I have not achieved this and have the following working

code at
present.

Sub AddMenu2()
MenuBars(xlWorksheet).Menus.Add Caption:="Test", befo="File"
With MenuBars(xlWorksheet).Menus("Test").MenuItems
.Add Caption:="Test1", OnAction:="Test1"
.Add Caption:="Test2", OnAction:="Test2"
(etc.)
End With
End Sub

Sub Test1()
Call Main(1)
End Sub

Sub Test2()
Call Main(2)
End Sub
(Etc.)

Sub Main(intTest As Integer)
'Use intTest as a row lookup parameter _
and do something with it
End Sub

What I want to do is cut out the middle Procs (Test1, Test2 etc)

and
call
the 'Main' proc directly from the menu, passing it the integer

parameter
at
the same time. Such as like this:-

.Add Caption:="Test1", OnAction:="Main(1)"
.Add Caption:="Test2", OnAction:="Main(2)"

Which obviously does not work.
I have done this before, but:-
a. Can't remember how, and experimenting leads to failure
b. I think that it seemed to call the 'Main' twice for some

reason or
another.

TIA
Trevor












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
Problems with Edit Menu Paul S Setting up and Configuration of Excel 2 January 24th 07 11:50 PM
Menu and Form problems moonhk Excel Programming 2 November 23rd 06 03:04 PM
Toolbar Menu problems Nigel Excel Programming 4 April 10th 05 02:29 PM
Custom menu problems Andrew Fletcher Excel Programming 5 April 3rd 05 01:42 PM
Problems with Excel 2003 Help menu BareBamboo Excel Discussion (Misc queries) 2 December 1st 04 07:29 PM


All times are GMT +1. The time now is 07:25 AM.

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

About Us

"It's about Microsoft Excel"