Code exected at "Workbook Open" slowing/stopping file from opening

R

robs3131

Hi all,

I'm in process of completing a spreadsheet with a lot of custom macros that
will be used by a lot of different people. Some of the macros require the
"Analysis Toolpak" and "Solver" add-ins. As a result, I have the two subs
below executing at "Workbook_Open" (they are the same macro really, one
specific to "Analysis Toolpak" and one specific to "Solver").

The issue I'm having is that over time, it takes longer and longer to open -
sometimes it just freezes up. When it freezes up, I use Task Manager to
close Excel -- when I try to open the file again, Vista (my OS) recommends
that I don't add in Solver or Analysis Toolpak as they caused a serious error
the last time I attempted to open the file. Wondering if anyone knows what
exactly in the code would be causing the issue and/or how to get around it?

FYI - when I used "Code Cleaner"
(http://www.appspro.com/Utilities/CodeCleaner.htm), this restores the file to
openinig quickly again. However, within 20 times of opening the file, the
issue resurfaces.

Also, the code for the add-ins was taken from the "Peltier Technical
Services" website (http://peltiertech.com/Excel/SolverVBA.html).

Code:
-----------------------------
Private Sub Workbook_Open()

Module22.CheckSolver
Module22.CheckAntoolpak

End Sub
-----------------------------
Public Function CheckSolver() As Boolean
'' Adjusted for Application.Run() to avoid Reference problems with Solver
'' Peltier Technical Services, Inc., Copyright © 2007. All rights reserved.
'' Returns True if Solver can be used, False if not.

Dim bSolverInstalled As Boolean

If gbDebug Then Debug.Print Now, "CheckSolver "
'' Assume true unless otherwise
CheckSolver = True

On Error Resume Next
' check whether Solver is installed
bSolverInstalled = Application.AddIns("Solver Add-In").Installed
Err.Clear

If bSolverInstalled Then
' uninstall temporarily
Application.AddIns("Solver Add-In").Installed = False
' check whether Solver is installed (should be false)
bSolverInstalled = Application.AddIns("Solver Add-In").Installed
End If

If Not bSolverInstalled Then
' (re)install Solver
Application.AddIns("Solver Add-In").Installed = True
' check whether Solver is installed (should be true)
bSolverInstalled = Application.AddIns("Solver Add-In").Installed
End If

If Not bSolverInstalled Then
MsgBox "Solver not found. This workbook will not work.", vbCritical
CheckSolver = False
End If

If CheckSolver Then
' initialize Solver
Application.Run "Solver.xla!Solver.Solver2.Auto_open"
End If

On Error GoTo 0

End Function
----------------------------------------
Public Function CheckAntoolpak() As Boolean
'' Adjusted for Application.Run() to avoid Reference problems with
Analysis ToolPak
'' Peltier Technical Services, Inc., Copyright © 2007. All rights reserved.
'' Returns True if Analysis ToolPak can be used, False if not.

Dim bantoolpakInstalled As Boolean

If gbDebug Then Debug.Print Now, "Checkantoolpak "
'' Assume true unless otherwise
CheckAntoolpak = True

On Error Resume Next
' check whether Analysis ToolPak is installed
bantoolpakInstalled = Application.AddIns("Analysis ToolPak").Installed
Err.Clear

If bantoolpakInstalled Then
' uninstall temporarily
Application.AddIns("Analysis ToolPak").Installed = False
' check whether Analysis ToolPak is installed (should be false)
bantoolpakInstalled = Application.AddIns("Analysis ToolPak").Installed
End If

If Not bantoolpakInstalled Then
' (re)install Analysis ToolPak
Application.AddIns("Analysis ToolPak").Installed = True
' check whether Analysis ToolPak is installed (should be true)
bantoolpakInstalled = Application.AddIns("Analysis ToolPak").Installed
End If

If Not bantoolpakInstalled Then
MsgBox "Analysis ToolPak not found. This workbook will not work.",
vbCritical
CheckAntoolpak = False
End If

If CheckAntoolpak Then
' initialize Analysis ToolPak
Application.Run "Analysis ToolPak.xla!Analysis ToolPak.Auto_open"
End If

On Error GoTo 0

End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top