Option Explicit
Private Enum vbaConsts
vbext_pp_locked = 1
vbext_pp_none = 0
vbext_ws_Maximize = 2
vbext_ws_Minimize = 1
vbext_ws_Normal = 0
End Enum
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim wb As Workbook
Dim strMsg As String
Dim md As Object '<-- VBComponent
Dim bolFoundModule As Boolean
Dim bolWBMissing As Boolean
'// However you wanted to limit the range... //
If Target.Column = 1 And Target.Row > 1 _
And Target.Row < 20 Then
Cancel = True
'// If I was going to actually check other wb's, I'd probably throw from here //
'// down into a function //
On Error Resume Next
'Set wb = Workbooks("xxxTempTestLockedProject(EmptyProject).xls")
Set wb = ThisWorkbook
bolWBMissing = CBool(Err)
On Error GoTo 0
If Not bolWBMissing Then
If ProjectAccessPossible(wb, strMsg) Then
For Each md In wb.VBProject.VBComponents
If md.Name = Target.Text Then
'// I chose to use .CodePane, as this seems to work for both //
'// Standard and Class modules. //
wb.VBProject.VBComponents(Target.Text).VBE.MainWindow.Visible = True
wb.VBProject.VBComponents(Target.Text).CodeModule.CodePane.Show
wb.Application.VBE.MainWindow.WindowState = vbext_ws_Maximize
wb.Application.VBE.ActiveWindow.WindowState = vbext_ws_Maximize
bolFoundModule = True
Exit For
End If
Next
If Not bolFoundModule Then
MsgBox "I was unable to find a module named: " & Selection.Value, vbInformation, vbNullString
End If
Else
MsgBox strMsg, vbCritical Or vbOKOnly, "Error!"
End If
Else
MsgBox "Unable to reference wb...", vbInformation, vbNullString
End If
End If
'...other statements...
End Sub
Private Function ProjectAccessPossible(ByVal wb As Workbook, ByRef MsgString As String) As Boolean
Dim lErrorCheck As Long
Dim bolAccessTrusted As Boolean
'// Seems to catch whether access is trusted, while not being fooled if the project //
'// is simply locked. //
On Error Resume Next
bolAccessTrusted = CBool(Len(wb.Parent.VBE.MainWindow.Caption))
On Error GoTo 0
'// If access is not trusted, the elseif doesn't get evaluated, so no foul. //
If Not bolAccessTrusted Then
MsgString = "Reference: " & wb.Name & vbCrLf & vbCrLf & _
"Programmatic Access to Visual Basic Project is not trusted" & vbCrLf & _
Space(4) & "This is an application controlled option and must be set by you."
ElseIf wb.VBProject.Protection = vbext_pp_locked Then
MsgString = wb.Name & "'s VBProject is locked for viewing."
'// Just clarity; I think an Else would be fine. //
ElseIf bolAccessTrusted And wb.VBProject.Protection = vbext_pp_none Then
ProjectAccessPossible = True
End If
End Function