Without looking too deeply at your code... I don't see anything to delete the previously created button and code, or to check if it already exists, so that's bound to create problems. I gave an example for this in the KB as a "how to" but I certainly wouldn't recommend that approach (it's also not a good example either).Originally Posted by trpltongue
If you're still determined, as far as access is concerned, you could call something like this from a Workbook_Open procedure...
[vba]
Private Sub AddRefsIfAccessAllowed()
Dim Response As VbMsgBoxResult
'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
Response = 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 to show the security dialog" & 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" & vbNewLine & vbNewLine & _
"Do you want the security dialog shown now?", vbYesNoCancel + vbCritical)
If Response = vbYes Then Application.CommandBars("Macro").Controls("Security...").Execute
Exit Sub
End If
End If
'Call AddReference
End Sub[/vba]