Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default Working with Menu Bars / Toolbars problem

Excel Helper

I have recently built a spreadsheet with 5 worksheets.

In worksheet 1 I had a set up whereby if a user right-clicked in column
3,4,5 then a drop down menu appeared and the usual short-cut menu was
suppressed.

Here is my code:

Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As
Boolean)

Dim cbBar As CommandBar
Set cbBar = CommandBars("Cell")

If Selection.Column = 3 Then

cbBar.Enabled = False
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop,
Operator:=xlBetween, Formula1:="=Names"
End With

ElseIf Selection.Column = 4 Then
cbBar.Enabled = False
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop,
Operator:=xlBetween, Formula1:="=Suppliers"
End With

ElseIf Selection.Column = 5 Then
cbBar.Enabled = False
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop,
Operator:=xlBetween, Formula1:="=Parts"
End With

Else
cbBar.Enabled = True

End If

End Sub

I have two problems with this code:

1) If I click in columns 3,4 and 5 it works fine. However, if I then go into
a different worksheet and right-click the short cut menu does not appear,
EVEN THOUGH the code above is placed in the Sheet 1 code module. It seems
that once the short-cut menu is disabled it remains that way. Any ideas?

2) Related to point (1), when I closed this workbook and opened up a
separate workbook the right-click short-cut was still disabled. I am aware
that a change to a menu bar will appear in all subsequent workbooks (unless
you use event handling) but was surprised to see that the right-click
disabling had been inherited too. Again, any ideas?

As always I am grateful for any guidance.

Regards

Alex
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Working with Menu Bars / Toolbars problem

Instead of disabling the Cell commandbar, you can just add:

Cancel = true

to your code.

That suppresses that popup menu.

Kind of like:

Option Explicit

Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, _
Cancel As Boolean)

If Intersect(Target, Me.Range("c:e")) Is Nothing Then Exit Sub

Cancel = True 'stop the popup

If Target.Column = 3 Then
With Target.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, Formula1:="=Names"
End With
ElseIf Target.Column = 4 Then
With Target.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, Formula1:="=Suppliers"
End With
ElseIf Target.Column = 5 Then
With Target.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, Formula1:="=Parts"
End With
End If

End Sub

But since your code looks pretty much the same, you may want to do it like this:

Option Explicit
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, _
Cancel As Boolean)

Dim myFormula As String

If Intersect(Target, Me.Range("c:e")) Is Nothing Then Exit Sub

Cancel = True 'stop the popup

Select Case Target.Column
Case Is = 3: myFormula = "=Names"
Case Is = 4: myFormula = "=Suppliers"
Case Is = 5: myFormula = "=Parts"
Case Else
MsgBox "design error--contact alex"
Exit Sub
End Select

With Target.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, Formula1:=myFormula
End With

End Sub



Alex wrote:

Excel Helper

I have recently built a spreadsheet with 5 worksheets.

In worksheet 1 I had a set up whereby if a user right-clicked in column
3,4,5 then a drop down menu appeared and the usual short-cut menu was
suppressed.

Here is my code:

Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As
Boolean)

Dim cbBar As CommandBar
Set cbBar = CommandBars("Cell")

If Selection.Column = 3 Then

cbBar.Enabled = False
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop,
Operator:=xlBetween, Formula1:="=Names"
End With

ElseIf Selection.Column = 4 Then
cbBar.Enabled = False
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop,
Operator:=xlBetween, Formula1:="=Suppliers"
End With

ElseIf Selection.Column = 5 Then
cbBar.Enabled = False
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop,
Operator:=xlBetween, Formula1:="=Parts"
End With

Else
cbBar.Enabled = True

End If

End Sub

I have two problems with this code:

1) If I click in columns 3,4 and 5 it works fine. However, if I then go into
a different worksheet and right-click the short cut menu does not appear,
EVEN THOUGH the code above is placed in the Sheet 1 code module. It seems
that once the short-cut menu is disabled it remains that way. Any ideas?

2) Related to point (1), when I closed this workbook and opened up a
separate workbook the right-click short-cut was still disabled. I am aware
that a change to a menu bar will appear in all subsequent workbooks (unless
you use event handling) but was surprised to see that the right-click
disabling had been inherited too. Again, any ideas?

As always I am grateful for any guidance.

Regards

Alex


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Working with Menu Bars / Toolbars problem

And add this one line to the top of each procedu

set target = target.cells(1)

This will avoid any problem if you have multiple cells selected when you do the
right click.



Dave Peterson wrote:

Instead of disabling the Cell commandbar, you can just add:

Cancel = true

to your code.

That suppresses that popup menu.

Kind of like:

Option Explicit

Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, _
Cancel As Boolean)

If Intersect(Target, Me.Range("c:e")) Is Nothing Then Exit Sub

Cancel = True 'stop the popup

If Target.Column = 3 Then
With Target.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, Formula1:="=Names"
End With
ElseIf Target.Column = 4 Then
With Target.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, Formula1:="=Suppliers"
End With
ElseIf Target.Column = 5 Then
With Target.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, Formula1:="=Parts"
End With
End If

End Sub

But since your code looks pretty much the same, you may want to do it like this:

Option Explicit
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, _
Cancel As Boolean)

Dim myFormula As String

If Intersect(Target, Me.Range("c:e")) Is Nothing Then Exit Sub

Cancel = True 'stop the popup

Select Case Target.Column
Case Is = 3: myFormula = "=Names"
Case Is = 4: myFormula = "=Suppliers"
Case Is = 5: myFormula = "=Parts"
Case Else
MsgBox "design error--contact alex"
Exit Sub
End Select

With Target.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, Formula1:=myFormula
End With

End Sub

Alex wrote:

Excel Helper

I have recently built a spreadsheet with 5 worksheets.

In worksheet 1 I had a set up whereby if a user right-clicked in column
3,4,5 then a drop down menu appeared and the usual short-cut menu was
suppressed.

Here is my code:

Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As
Boolean)

Dim cbBar As CommandBar
Set cbBar = CommandBars("Cell")

If Selection.Column = 3 Then

cbBar.Enabled = False
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop,
Operator:=xlBetween, Formula1:="=Names"
End With

ElseIf Selection.Column = 4 Then
cbBar.Enabled = False
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop,
Operator:=xlBetween, Formula1:="=Suppliers"
End With

ElseIf Selection.Column = 5 Then
cbBar.Enabled = False
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop,
Operator:=xlBetween, Formula1:="=Parts"
End With

Else
cbBar.Enabled = True

End If

End Sub

I have two problems with this code:

1) If I click in columns 3,4 and 5 it works fine. However, if I then go into
a different worksheet and right-click the short cut menu does not appear,
EVEN THOUGH the code above is placed in the Sheet 1 code module. It seems
that once the short-cut menu is disabled it remains that way. Any ideas?

2) Related to point (1), when I closed this workbook and opened up a
separate workbook the right-click short-cut was still disabled. I am aware
that a change to a menu bar will appear in all subsequent workbooks (unless
you use event handling) but was surprised to see that the right-click
disabling had been inherited too. Again, any ideas?

As always I am grateful for any guidance.

Regards

Alex


--

Dave Peterson


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default Working with Menu Bars / Toolbars problem

Dave

Thanks for that. It worked really well.

I was impressed by your second piece of code. Much neater than my poor
effort and more effective too.

Again, thanks for taking the time to pass on your knowledge.

Regards


Alex

"Dave Peterson" wrote:

Instead of disabling the Cell commandbar, you can just add:

Cancel = true

to your code.

That suppresses that popup menu.

Kind of like:

Option Explicit

Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, _
Cancel As Boolean)

If Intersect(Target, Me.Range("c:e")) Is Nothing Then Exit Sub

Cancel = True 'stop the popup

If Target.Column = 3 Then
With Target.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, Formula1:="=Names"
End With
ElseIf Target.Column = 4 Then
With Target.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, Formula1:="=Suppliers"
End With
ElseIf Target.Column = 5 Then
With Target.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, Formula1:="=Parts"
End With
End If

End Sub

But since your code looks pretty much the same, you may want to do it like this:

Option Explicit
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, _
Cancel As Boolean)

Dim myFormula As String

If Intersect(Target, Me.Range("c:e")) Is Nothing Then Exit Sub

Cancel = True 'stop the popup

Select Case Target.Column
Case Is = 3: myFormula = "=Names"
Case Is = 4: myFormula = "=Suppliers"
Case Is = 5: myFormula = "=Parts"
Case Else
MsgBox "design error--contact alex"
Exit Sub
End Select

With Target.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, Formula1:=myFormula
End With

End Sub



Alex wrote:

Excel Helper

I have recently built a spreadsheet with 5 worksheets.

In worksheet 1 I had a set up whereby if a user right-clicked in column
3,4,5 then a drop down menu appeared and the usual short-cut menu was
suppressed.

Here is my code:

Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As
Boolean)

Dim cbBar As CommandBar
Set cbBar = CommandBars("Cell")

If Selection.Column = 3 Then

cbBar.Enabled = False
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop,
Operator:=xlBetween, Formula1:="=Names"
End With

ElseIf Selection.Column = 4 Then
cbBar.Enabled = False
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop,
Operator:=xlBetween, Formula1:="=Suppliers"
End With

ElseIf Selection.Column = 5 Then
cbBar.Enabled = False
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop,
Operator:=xlBetween, Formula1:="=Parts"
End With

Else
cbBar.Enabled = True

End If

End Sub

I have two problems with this code:

1) If I click in columns 3,4 and 5 it works fine. However, if I then go into
a different worksheet and right-click the short cut menu does not appear,
EVEN THOUGH the code above is placed in the Sheet 1 code module. It seems
that once the short-cut menu is disabled it remains that way. Any ideas?

2) Related to point (1), when I closed this workbook and opened up a
separate workbook the right-click short-cut was still disabled. I am aware
that a change to a menu bar will appear in all subsequent workbooks (unless
you use event handling) but was surprised to see that the right-click
disabling had been inherited too. Again, any ideas?

As always I am grateful for any guidance.

Regards

Alex


--

Dave Peterson

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Working with Menu Bars / Toolbars problem

Don't forget to add that extra line, too. It may come back to haunt you if you
don't.

Alex wrote:

Dave

Thanks for that. It worked really well.

I was impressed by your second piece of code. Much neater than my poor
effort and more effective too.

Again, thanks for taking the time to pass on your knowledge.

Regards

Alex

"Dave Peterson" wrote:

Instead of disabling the Cell commandbar, you can just add:

Cancel = true

to your code.

That suppresses that popup menu.

Kind of like:

Option Explicit

Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, _
Cancel As Boolean)

If Intersect(Target, Me.Range("c:e")) Is Nothing Then Exit Sub

Cancel = True 'stop the popup

If Target.Column = 3 Then
With Target.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, Formula1:="=Names"
End With
ElseIf Target.Column = 4 Then
With Target.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, Formula1:="=Suppliers"
End With
ElseIf Target.Column = 5 Then
With Target.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, Formula1:="=Parts"
End With
End If

End Sub

But since your code looks pretty much the same, you may want to do it like this:

Option Explicit
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, _
Cancel As Boolean)

Dim myFormula As String

If Intersect(Target, Me.Range("c:e")) Is Nothing Then Exit Sub

Cancel = True 'stop the popup

Select Case Target.Column
Case Is = 3: myFormula = "=Names"
Case Is = 4: myFormula = "=Suppliers"
Case Is = 5: myFormula = "=Parts"
Case Else
MsgBox "design error--contact alex"
Exit Sub
End Select

With Target.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, Formula1:=myFormula
End With

End Sub



Alex wrote:

Excel Helper

I have recently built a spreadsheet with 5 worksheets.

In worksheet 1 I had a set up whereby if a user right-clicked in column
3,4,5 then a drop down menu appeared and the usual short-cut menu was
suppressed.

Here is my code:

Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As
Boolean)

Dim cbBar As CommandBar
Set cbBar = CommandBars("Cell")

If Selection.Column = 3 Then

cbBar.Enabled = False
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop,
Operator:=xlBetween, Formula1:="=Names"
End With

ElseIf Selection.Column = 4 Then
cbBar.Enabled = False
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop,
Operator:=xlBetween, Formula1:="=Suppliers"
End With

ElseIf Selection.Column = 5 Then
cbBar.Enabled = False
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop,
Operator:=xlBetween, Formula1:="=Parts"
End With

Else
cbBar.Enabled = True

End If

End Sub

I have two problems with this code:

1) If I click in columns 3,4 and 5 it works fine. However, if I then go into
a different worksheet and right-click the short cut menu does not appear,
EVEN THOUGH the code above is placed in the Sheet 1 code module. It seems
that once the short-cut menu is disabled it remains that way. Any ideas?

2) Related to point (1), when I closed this workbook and opened up a
separate workbook the right-click short-cut was still disabled. I am aware
that a change to a menu bar will appear in all subsequent workbooks (unless
you use event handling) but was surprised to see that the right-click
disabling had been inherited too. Again, any ideas?

As always I am grateful for any guidance.

Regards

Alex


--

Dave Peterson


--

Dave Peterson
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
Eliminating Toolbars,Sheet Tabs,Scroll Bars. etc. mtm4300 via OfficeKB.com Excel Programming 3 February 16th 06 06:11 PM
Lost all my menu bars and tool bars CathyJ Excel Discussion (Misc queries) 3 August 8th 05 12:49 PM
Menu/toolbars/macros defined in Excel 2003 not working in other versions? aiyer[_34_] Excel Programming 2 August 13th 04 07:32 PM
New Menu on Worksheet & Chart Menu Bars Juan[_3_] Excel Programming 2 May 21st 04 11:46 PM
linking chart menu bars and worksheet menu bars majikman[_8_] Excel Programming 0 May 10th 04 09:45 PM


All times are GMT +1. The time now is 07:00 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"