-
In the ThisWorkbook module...
[VBA]
Private Sub Workbook_Open()
Call AddRefsIfAccessAllowed
End Sub
Private Sub AddRefsIfAccessAllowed()
' 'Test to ensure access is allowed
If Application.Version > 9 Then
Dim VisualBasicProject As Object
On Error Resume Next
Set VisualBasicProject = ActiveWorkbook.VBproject
If Not Err.Number = 0 Then
Msgbox "Your current security settings do not allow the code in this workbook " & vbNewLine & _
" to work as designed and you will get some error messages." & vbNewLine & vbNewLine & _
"To allow the code to function correctly and without errors you need" & vbNewLine & _
" to change your security setting as follows:" & vbNewLine & vbNewLine & _
" 1. Select Tools - Macro - Security." & vbNewLine & _
" 2. Click the 'Trusted Sources' tab" & vbNewLine & _
" 3. Place a checkmark next to 'Trust Access to Visual Basic Project.'" & vbNewLine & _
" 4. Save - then Close and re-open the workbook", _
vbCritical
Exit Sub
End If
End If
Call AddReference
End Sub
Private Sub AddReference()
Dim Reference As Object
With ThisWorkbook.VBproject
For Each Reference In .References
If Reference.Description Like "Microsoft Visual Basic for Applications Extensibility*" Then Exit Sub
Next
.References.AddFromGuid "{0002E157-0000-0000-C000-000000000046}", 5, 3
End With
End Sub
[/VBA]
-
-
thanks, my bad, I thought with allowing a minimum security level excel granted this access. thanks a lot, great articles by the way
-
Well, I don't have 2003 so I can't test the veracity of that statement, but from what I can gather the "Trust Access..." is a quite separate issue (Ta)