PC Review


Reply
Thread Tools Rate Thread

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

 
 
robs3131
Guest
Posts: n/a
 
      4th Mar 2008
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

--
Robert
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Possible to change default "All Open Workbooks" to "This Workbook" in macro dialogue box? StargateFanFromWork Microsoft Excel Discussion 0 4th Jan 2006 10:49 PM
How do you clear the "Open an existing file" list in the opening b =?Utf-8?B?Q1QtQ2Fyb2w=?= Microsoft Access Getting Started 2 30th Jun 2005 11:20 PM
Error boxes when opening Excel "unable to read file" then "open X. =?Utf-8?B?anBweg==?= Microsoft Excel Setup 1 19th Feb 2005 03:51 AM
AN EXTRA WORKBOOK IS OPENING NAMED "PERSONAL" EVERY TIME I OPEN A. =?Utf-8?B?ZGVubmlzaGlhdHRAbXNuLmNvbQ==?= Microsoft Excel Crashes 1 23rd Dec 2004 07:40 AM
How to code VBA to open "Open File Dialog Box" in MS ACCESS 2000 Jean Microsoft Access Getting Started 2 22nd Oct 2004 03:16 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:00 PM.