Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 389
Default Before right click:

I have this as the first lines of code under an open workbook in it's:

This Workbook
Apps
Private Sub App_SheetBeforeRightClick(ByVal Sh As Object, ByVal Target As
Range, Cancel As Boolean)

---code---
If ActiveSheet.ProtectContents = True And ActiveCell.Locked = True Then
With Application.CommandBars("Cell").Controls
.Item(2).Enabled = False
End With
Else
With Application.CommandBars("Cell").Controls
.Item(2).Enabled = True
End With
End If


It always will return True no matter if the workbook is protected or not.
But if I use the code above on a right click menu custom item after the item
is clicked then it correctly identifies if the sheet is protected or not.

What am I doing wrong here?

Thank you for your help.

Steven

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Before right click:

I'm not sure what is returning True (.item(2).enabled???).

But this worked ok for me:

Option Explicit
Public WithEvents App As Excel.Application
Private Sub Workbook_Open()
Set App = Application
End Sub
Private Sub Workbook_Close()
Set App = Nothing
End Sub
Private Sub App_SheetBeforeRightClick(ByVal Sh As Object, _
ByVal Target As Range, Cancel As Boolean)

If Sh.ProtectContents = True _
And Target.Cells(1).Locked = True Then
With Application.CommandBars("Cell").Controls
.Item(2).Enabled = False
End With
Else
With Application.CommandBars("Cell").Controls
.Item(2).Enabled = True
End With
End If
End Sub

(I had all the code in the ThisWorkbook module.)

Since excel passes the sheet (as Sh) and the range (as Target), I'd use them.

Steven wrote:

I have this as the first lines of code under an open workbook in it's:

This Workbook
Apps
Private Sub App_SheetBeforeRightClick(ByVal Sh As Object, ByVal Target As
Range, Cancel As Boolean)

---code---
If ActiveSheet.ProtectContents = True And ActiveCell.Locked = True Then
With Application.CommandBars("Cell").Controls
.Item(2).Enabled = False
End With
Else
With Application.CommandBars("Cell").Controls
.Item(2).Enabled = True
End With
End If

It always will return True no matter if the workbook is protected or not.
But if I use the code above on a right click menu custom item after the item
is clicked then it correctly identifies if the sheet is protected or not.

What am I doing wrong here?

Thank you for your help.

Steven


--

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
How to change syperlink from single click to double click syperlinker Excel Worksheet Functions 0 June 13th 08 05:01 PM
Disabling click and right-click on the Picture I inserted in an Excel document [email protected] Excel Worksheet Functions 1 June 2nd 06 09:13 PM
userform label double-click goes to click event John Paul Fullerton Excel Programming 3 May 19th 06 05:54 PM
Click on graph bar to execute a double-click in a pivot table cell [email protected] Charts and Charting in Excel 4 August 3rd 05 01:37 AM
Mouse Over Graph, Capture Information on Click(Double Click) Dean Hinson[_3_] Excel Programming 1 December 6th 04 04:49 AM


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