MagicCarpet
New Member
- Joined
- Aug 1, 2024
- Messages
- 3
- Office Version
- 2010
- Platform
- Windows
I have below code and need to use it in an password protected sheet. I tried but not working.
""
________________________________________________________________________________________________________________________________________________
Private Sub Worksheet_BeforeDoubleClick _
(ByVal Target As Range, _
Cancel As Boolean)
'ThisWorkbook.Sheets("FATURA").Unprotect password:="lomokafr"
Dim str As String
Dim cboTemp As OLEObject
Dim ws As Worksheet
Set ws = Sheet1
Set cboTemp = ws.OLEObjects("TempCombo")
On Error Resume Next
With cboTemp
.ListFillRange = ""
.LinkedCell = ""
.Visible = False
End With
On Error GoTo errHandler
If Target.Validation.Type = 3 Then
'if the cell contains a data validation list
Cancel = True
'get the data validation formula
str = Target.Validation.Formula1
str = Right(str, Len(str) - 1)
With cboTemp
'show the combobox with the list
.Visible = True
.Left = Target.Left
.Top = Target.Top
.Width = Target.Width + 5
.Height = Target.Height + 5
.ListFillRange = str
.LinkedCell = Target.Address
End With
cboTemp.Activate
'open the drop down list automatically
Me.TempCombo.DropDown
End If
errHandler:
'ThisWorkbook.Sheets("FATURA").Protect password:="lomokafr"
Exit Sub
End Sub
_____________________________________________________________________________________________________________________________________________________________________________
Private Sub TempCombo_LostFocus()
'ThisWorkbook.Sheets("FATURA").Unprotect password:="lomokafr"
With Me.TempCombo
.Top = 5
.Left = 5
.Width = 0
.ListFillRange = ""
.LinkedCell = ""
.Visible = False
.Value = ""
End With
'ThisWorkbook.Sheets("FATURA").Protect password:="lomokafr"
End Sub
_______________________________________________________________________________________________________________________________________________________________________________
Private Sub TempCombo_KeyDown(ByVal _
KeyCode As MSForms.ReturnInteger, _
ByVal Shift As Integer)
'ThisWorkbook.Sheets("FATURA").Unprotect password:="lomokafr"
Select Case KeyCode
Case 9 'Tab
ActiveCell.Offset(0, 1).Activate
Case 13 'Enter
ActiveCell.Offset(1, 0).Activate
Case Else
'do nothing
End Select
'ThisWorkbook.Sheets("FATURA").Protect password:="lomokafr"
End Sub
""
""
________________________________________________________________________________________________________________________________________________
Private Sub Worksheet_BeforeDoubleClick _
(ByVal Target As Range, _
Cancel As Boolean)
'ThisWorkbook.Sheets("FATURA").Unprotect password:="lomokafr"
Dim str As String
Dim cboTemp As OLEObject
Dim ws As Worksheet
Set ws = Sheet1
Set cboTemp = ws.OLEObjects("TempCombo")
On Error Resume Next
With cboTemp
.ListFillRange = ""
.LinkedCell = ""
.Visible = False
End With
On Error GoTo errHandler
If Target.Validation.Type = 3 Then
'if the cell contains a data validation list
Cancel = True
'get the data validation formula
str = Target.Validation.Formula1
str = Right(str, Len(str) - 1)
With cboTemp
'show the combobox with the list
.Visible = True
.Left = Target.Left
.Top = Target.Top
.Width = Target.Width + 5
.Height = Target.Height + 5
.ListFillRange = str
.LinkedCell = Target.Address
End With
cboTemp.Activate
'open the drop down list automatically
Me.TempCombo.DropDown
End If
errHandler:
'ThisWorkbook.Sheets("FATURA").Protect password:="lomokafr"
Exit Sub
End Sub
_____________________________________________________________________________________________________________________________________________________________________________
Private Sub TempCombo_LostFocus()
'ThisWorkbook.Sheets("FATURA").Unprotect password:="lomokafr"
With Me.TempCombo
.Top = 5
.Left = 5
.Width = 0
.ListFillRange = ""
.LinkedCell = ""
.Visible = False
.Value = ""
End With
'ThisWorkbook.Sheets("FATURA").Protect password:="lomokafr"
End Sub
_______________________________________________________________________________________________________________________________________________________________________________
Private Sub TempCombo_KeyDown(ByVal _
KeyCode As MSForms.ReturnInteger, _
ByVal Shift As Integer)
'ThisWorkbook.Sheets("FATURA").Unprotect password:="lomokafr"
Select Case KeyCode
Case 9 'Tab
ActiveCell.Offset(0, 1).Activate
Case 13 'Enter
ActiveCell.Offset(1, 0).Activate
Case Else
'do nothing
End Select
'ThisWorkbook.Sheets("FATURA").Protect password:="lomokafr"
End Sub
""