View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default Code to install Analysis ToolPak at Workbook Open

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

"robs3131" wrote in message
...
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

--
Robert