CheckSolver causing me a problem

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 Auto_Open()

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
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Checksolver is a Function that returns a value of TRUE or FALSE. It is not a Sub procedure

You cannot just call Checksolver. You have to set a variable to it e.g.
Code:
Dim x As Boolean
x = Checksolver
...and then do something with the variable x.


Or test the result of Checksolver...
Code:
If Checksolver Then
   'Solver is installed
Else
   'Solver not installed
End If
 
Upvote 0
Many thanks for your quick response.

I want to be able to send the file to a client and have it make sure that Solver is installed. Will the following code achieve that end for me?

"Sub Auto_Open()

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
Application.AddIns("Solver Add-In").Installed = True
Application.Run "Solver.xlam!Solver.Solver2.Auto_open"
ShowMenus = True
CreateMenu
ShowSheets
Sheets("snapshotinput").Select
ActiveWindow.DisplayWorkbookTabs = False

End Sub"

Thanks again

John from WA
 
Upvote 0

Forum statistics

Threads
1,225,072
Messages
6,182,699
Members
453,132
Latest member
nsnodgrass73

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top