Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Context Menu Commandbar Question

Windows XP Pro SP2
Excel 2003 SP3

When I right click anywhere on a worksheet I get the standard Excel context
menu. What commandbar is this, and how would I add a macro item to it?

TIA!

-gk-



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 638
Default Context Menu Commandbar Question

That is the Cells menubar. You add something to it like:
Dim MenuObject As Object
Set MenuObject = Application.CommandBars("Cell"). _
Controls.Add(Type:=msoControlButton)
With MenuObject
.Caption = "Whatever"
.OnAction="Module1.macroName"
End With
Set MenuObject = Nothing

You could then incorporate code to loop though the menu when the
applicable workbook is closed and remove the button, if you so choose.
Sandusky wrote:
Windows XP Pro SP2
Excel 2003 SP3

When I right click anywhere on a worksheet I get the standard Excel context
menu. What commandbar is this, and how would I add a macro item to it?

TIA!

-gk-


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Context Menu Commandbar Question

It's the "Cell" menubar.

Saved from a previous post:

You can modify that rightclick popup in code.

If you want this functionality available for every workbook you open, you can
put the code into a workbook that opens each time excel opens.

Most people would use a file by the name of personal.xls and store it in their
XLStart folder.

If you only want it to work on a specific workbook, you can put the code in that
workbook.

This is what the code could look like:

Option Explicit
Sub auto_open()
With Application.CommandBars("cell")
On Error Resume Next
.Controls("Print Selection").Delete
On Error GoTo 0

With .Controls.Add(Type:=msoControlButton, temporary:=True)
.BeginGroup = True
.Caption = "Print Selection"
.OnAction = "'" & ThisWorkbook.Name & "'!PrintMySelection"
End With
End With
End Sub
Sub auto_close()
With Application.CommandBars("cell")
On Error Resume Next
.Controls("Print Selection").Delete
On Error GoTo 0
End With
End Sub
Sub PrintMySelection()
If Selection.Cells.Count = 1 Then
Beep 'why print one cell?
Else
'save paper while testing
Selection.PrintOut preview:=True
End If
End Sub

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

This code goes in a general module in either case (personal.xls or the specific
workbook).

Sandusky wrote:

Windows XP Pro SP2
Excel 2003 SP3

When I right click anywhere on a worksheet I get the standard Excel context
menu. What commandbar is this, and how would I add a macro item to it?

TIA!

-gk-


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Context Menu Commandbar Question


"Sandusky" wrote in message
...
Windows XP Pro SP2
Excel 2003 SP3

When I right click anywhere on a worksheet I get the standard Excel
context
menu. What commandbar is this, and how would I add a macro item to it?

TIA!

-gk-


Thank you both! Works like a charm.

Sorry about the double post.

-gk-


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
Context Menu (Sub-Menu Disable/Enable) JR_06062005[_2_] Excel Programming 4 August 31st 06 06:01 PM
Disable Sub-Menu of a Context Menu JR_06062005[_2_] Excel Programming 1 August 29th 06 09:46 PM
access [contextual||context||right-click] [menu||commandbar] of ch mrmack Excel Programming 0 June 21st 06 09:32 AM
Context menu cmpcwil2[_27_] Excel Programming 4 June 14th 06 12:11 PM
context menu eric23 Excel Programming 3 May 9th 04 11:49 PM


All times are GMT +1. The time now is 11:24 AM.

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"