View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Matthew Pfluger Matthew Pfluger is offline
external usenet poster
 
Posts: 130
Default Addin Auto_Open code executes only in debug mode

I am building a setup workbook that installs some custom addins. One of the
addins is giving me problems. The addin contains an Auto_Open procedure as
follows (note the DEBUG line at the end):

Public Sub Auto_Open()

' Initialize variables
Const szSOURCE As String = "Auto_Open" ' Module location
string for errorhandler
Dim bOpenFailed As Boolean ' Errorhandler
variable if commandbar code failed

On Error GoTo ErrorHandler
Application.ScreenUpdating = False

' Do stuff: build commandbars, register UDFs, etc.

ErrorExit:
On Error Resume Next

ResetAppProperties
If bOpenFailed Then ShutdownApplication

Debug.Print "I completed the startup code!!!"

Exit Sub

ErrorHandler:
bOpenFailed = True
Resume ErrorExit
End Sub

The Setup Workbook contains this code snippet in its Install procedu
' Attempt to uninstall addin to make sure it's gone (see uninstall code
below)
On Error Resume Next
If Not bUninstallAddin(sAddinName) Then Err.Raise glHANDLED_ERROR
On Error GoTo ErrorHandler

' Install addin
With AddIns.Add(Filename:=sAddinSourceFilepath, CopyFile:=bCopyToLibrary)
.Installed = True
End With

' *************** UNINSTALL CODE ************
' Attempt to close addin in case it is open
On Error Resume Next
AddIns(sAddinName).Installed = False
On Error GoTo ErrorHandler

' Delete registry keys (if any)
If Not bDeleteAddinRegistryKey(sAddinName) Then Err.Raise glHANDLED_ERROR
' *************** UNINSTALL CODE ************

I know from testing that the Uninstall code completely uninstalls the addin,
including running its Auto_Close script.

If the addin has been previously uninstalled, the Install code executes
completely, including running the addin's Auto_Open script. If I step
through the Install procedure, the addin installs completely, including
running the Auto_Open script. I know the Auto_Open script runs because the
DEBUG line prints a record of the execution in the Immediate Window.

However, in the case where the addin is already installed and I run the
Install macro without stepping through, the addin is installed at the end,
but the Auto_Open macro doesn't run (no record in Immediate Pane). A check
in the Add-In Manager and the VBE reveals that the addin is in fact open, but
why wouldn't the Auto_Open script run under these circumstances?

I know this is a little OCD, but the end user could initiate this situation
and would likely freak out, so I'm trying to cover all bases. Thanks for any
input.
Matthew Pfluger