Code to install Analysis ToolPak at Workbook Open

R

robs3131

Hi,

I need to have Analysis Toolpak auto-installed when my workbook is opened --
I tried to modify code that I have to auto-install Solver (which works for
Solver), however, it is not working for Analysis ToolPak. Any idea why this
is not working? FYI - the original code to install Solver was copied from
"Peltier Technical Services" website
(http://peltiertech.com/Excel/SolverVBA.html).

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
Add-In").Installed
Err.Clear

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

If Not bantoolpakInstalled Then
' (re)install Analysis ToolPak
Application.AddIns("Analysis ToolPak Add-In").Installed = True
' check whether Analysis ToolPak is installed (should be true)
bantoolpakInstalled = Application.AddIns("Analysis ToolPak
Add-In").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
 
P

Peter T

Hi Robert,

Try changing -

"Analysis ToolPak Add-In"
to
"Analysis ToolPak"

or, if you want the ATP addin for use with VBA
"Analysis ToolPak - VBA"

Regards,
Peter T
 
R

robs3131

Thanks Peter! That fixed it!

--
Robert


Peter T said:
Hi Robert,

Try changing -

"Analysis ToolPak Add-In"
to
"Analysis ToolPak"

or, if you want the ATP addin for use with VBA
"Analysis ToolPak - VBA"

Regards,
Peter T
 

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