John from WA
New Member
- Joined
- Feb 13, 2007
- Messages
- 5
Hi, I have used a module from this forum to check the existence of Solver but it is causing a "Run time error 9" for me.
This is the code I have inserted
"Public Function CheckSolver() As Boolean
''Adjusted for Applications.Run() to avoid Reference problems with Solver
''Returns True if Solver can be used, False if not
Dim bSolverInstalled As Boolean
''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 yet. Please contact Linkage Solutions for assistance on 0405559611", vbCritical
CheckSolver = False
End If
''If CheckSolver Then
'''initialise Solver
''Application.Run "Solver.xlam!Solver.Solver2.Auto_open"
''End If
On Error GoTo 0
End Function
And this is the code to open the file
"Sub Autpen()
ShowMenus = False
Agreed = False
Sheets("Menu").Select
Disclaimer.Show
' Disclaimer.Show vbModal
If Not Agreed Then
Application.ActiveWorkbook.Close False
Exit Sub
End If
If Not Authorised() Then Exit Sub
'CheckSolver
ShowMenus = True
CreateMenu
ShowSheets
Sheets("snapshotinput").Select
ActiveWindow.DisplayWorkbookTabs = False
End Sub
If I remove the ' from CheckSolver here, I get the error message mentioned above. If I leave it in and don't call the function, the file works OK.
I'm very much a beginner to VBA so please don't assume I have much knowledge at all.
Thanks, John from WA
This is the code I have inserted
"Public Function CheckSolver() As Boolean
''Adjusted for Applications.Run() to avoid Reference problems with Solver
''Returns True if Solver can be used, False if not
Dim bSolverInstalled As Boolean
''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 yet. Please contact Linkage Solutions for assistance on 0405559611", vbCritical
CheckSolver = False
End If
''If CheckSolver Then
'''initialise Solver
''Application.Run "Solver.xlam!Solver.Solver2.Auto_open"
''End If
On Error GoTo 0
End Function
And this is the code to open the file
"Sub Autpen()
ShowMenus = False
Agreed = False
Sheets("Menu").Select
Disclaimer.Show
' Disclaimer.Show vbModal
If Not Agreed Then
Application.ActiveWorkbook.Close False
Exit Sub
End If
If Not Authorised() Then Exit Sub
'CheckSolver
ShowMenus = True
CreateMenu
ShowSheets
Sheets("snapshotinput").Select
ActiveWindow.DisplayWorkbookTabs = False
End Sub
If I remove the ' from CheckSolver here, I get the error message mentioned above. If I leave it in and don't call the function, the file works OK.
I'm very much a beginner to VBA so please don't assume I have much knowledge at all.
Thanks, John from WA