PC Review


Reply
Thread Tools Rate Thread

Custom Context menu (Right click menu) not working in sheet changeevent.

 
 
Madiya
Guest
Posts: n/a
 
      11th Feb 2008
Hi all,
I face a small problem.

Following code works fine.
Sub ADD_COMMAND()
CommandBars("Cell").Reset
With Application.CommandBars("Cell").Controls
With .Add
.Caption = "OGP"
.OnAction = ThisWorkbook.Name & "OGP"
.Tag = OGPTAG
.BeginGroup = True
' .Temporary = True <<<<<< THIS LINE NOT WORKING
SO COMMENTED OUT
End With
End With
CommandBars("cell").Controls("OGP").FaceId = 44
End Sub

However, If I place the same code in worksheet activate event it does
not work.
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
If Sh.Name <> "ALVXXL01" Then
Exit Sub
End If
CommandBars("Cell").Reset <<<<<< error out
here .>>>>>>
With Application.CommandBars("Cell").Controls
With .Add
.Caption = "OGP"
.OnAction = ThisWorkbook.Name & "OGP"
.Tag = OGPTAG
.BeginGroup = True
' .Temporary = True
End With
End With
CommandBars("Cell").Controls("OGP").FaceId = 44
End Sub

Can somebody point out the mistake I am making please.

Regards,
Madiya
 
Reply With Quote
 
 
 
 
Jim Rech
Guest
Posts: n/a
 
      11th Feb 2008
>>' .Temporary = True <<<<<< THIS LINE NOT WORKING

A control does not have a Temporary property. Rather the Controls.Add
method has a Temporary parameter:

With Application.CommandBars("Cell").Controls
With .Add(Temporary:=True)
.Caption = "OGP"
''Etc.



>>CommandBars("Cell").Reset


Use:

Application.CommandBars("Cell").Reset

in a sheet or workbook module.


--
Jim
"Madiya" <(E-Mail Removed)> wrote in message
news:23b4d34b-4e9d-4756-b9a2-(E-Mail Removed)...
| Hi all,
| I face a small problem.
|
| Following code works fine.
| Sub ADD_COMMAND()
| CommandBars("Cell").Reset
| With Application.CommandBars("Cell").Controls
| With .Add
| .Caption = "OGP"
| .OnAction = ThisWorkbook.Name & "OGP"
| .Tag = OGPTAG
| .BeginGroup = True
| ' .Temporary = True <<<<<< THIS LINE NOT WORKING
| SO COMMENTED OUT
| End With
| End With
| CommandBars("cell").Controls("OGP").FaceId = 44
| End Sub
|
| However, If I place the same code in worksheet activate event it does
| not work.
| Private Sub Workbook_SheetActivate(ByVal Sh As Object)
| If Sh.Name <> "ALVXXL01" Then
| Exit Sub
| End If
| CommandBars("Cell").Reset <<<<<< error out
| here .>>>>>>
| With Application.CommandBars("Cell").Controls
| With .Add
| .Caption = "OGP"
| .OnAction = ThisWorkbook.Name & "OGP"
| .Tag = OGPTAG
| .BeginGroup = True
| ' .Temporary = True
| End With
| End With
| CommandBars("Cell").Controls("OGP").FaceId = 44
| End Sub
|
| Can somebody point out the mistake I am making please.
|
| Regards,
| Madiya


 
Reply With Quote
 
Madiya
Guest
Posts: n/a
 
      11th Feb 2008
Hi Jim,
Thanks for help. Perfact.
Another small problem. I am putting this macros in an addin.
I want to show custom button only if sheet name is "ALVXXL01".
If any other sheet is activated or any other file with different sheet
name is activated/opened then this control will be deleted.
If any file having same sheet name is activated then the control will
be shown up.

Will you pl advise, how shall I proceed?

Thanks again.
Regards,
Madiya.
 
Reply With Quote
 
Jim Rech
Guest
Posts: n/a
 
      11th Feb 2008
I might suggest that a far simpler way to go is to just check whether the
right sheet is active after the user clicks the button. To make a button
visible or not dynamically from an add-in you have to raise the bar quite a
bit in terms of complexity. But it's well worth learning about this area if
you really want to advance your developer skills.

http://support.microsoft.com/kb/213566

http://www.cpearson.com/excel/AppEvent.aspx



--
Jim
"Madiya" <(E-Mail Removed)> wrote in message
news:0b0c76a6-abdd-45cb-949a-(E-Mail Removed)...
| Hi Jim,
| Thanks for help. Perfact.
| Another small problem. I am putting this macros in an addin.
| I want to show custom button only if sheet name is "ALVXXL01".
| If any other sheet is activated or any other file with different sheet
| name is activated/opened then this control will be deleted.
| If any file having same sheet name is activated then the control will
| be shown up.
|
| Will you pl advise, how shall I proceed?
|
| Thanks again.
| Regards,
| Madiya.


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Right click menu (context menu) for Rows & col not working Madiya Microsoft Excel Programming 5 26th Dec 2009 10:07 AM
Project working with the context menu by right click in window explorer Cylix Microsoft VB .NET 0 21st Jun 2007 07:56 AM
Right Click Context Menu of a C# windows application not working o =?Utf-8?B?VEw=?= Microsoft Dot NET Framework 1 5th May 2007 05:53 AM
Highlight text and right click for a custom context menu, asp =?Utf-8?B?QWJkYWxsYQ==?= Microsoft ASP .NET 2 22nd Mar 2006 11:46 PM
Start Menu in Win XP Pro not displaying - right click context menu not working e Doug Windows XP Basics 1 28th Nov 2003 05:39 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:54 AM.