Paul Sansom
Board Regular
- Joined
- Jan 28, 2013
- Messages
- 178
- Office Version
- 2021
- 2016
- Platform
- Windows
Hi
I have a file that uses the solver function called from a reference. This works well.
The issue I see is that my users can have Solver in different locations e.g.
ForExcel 32bit program
For Info
Check if Solver is loaded
There is some unnecessary code here but I also check for 32/b4bit version for other uses.
Code to load solver reference (BUT LOCATION IS CURRENTLY HARD CODED a F92 or F93)
I have a file that uses the solver function called from a reference. This works well.
The issue I see is that my users can have Solver in different locations e.g.
ForExcel 32bit program
- The solver can resides in sub-dir
C:\Program Files (x86)\Microsoft Office\Office16\Library\SOLVER\
C:\Program Files (x86)\Microsoft Office\Office15\Library\SOLVER\
- The solver can reside in sub-dir
C:\Program Files\Microsoft Office\Root\Office16\Library\SOLVER\
For Info
Check if Solver is loaded
Code:
Sub Check_Solver_Reference()
' Check if not added then auto added[/FONT]
[FONT="Times New Roman"]''' Sheet11.Range("F80").ClearContents
Sheet11.Range("Win_64_32").ClearContents[/FONT]
[FONT="Times New Roman"] With ThisWorkbook.VBProject
For Each Ref In .References
If Ref.Name = "Solver" Then Sheet11.Range("F80") = True
Next
End With
' 'Check is Windows and Excel are 64 or 32 bit.
[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=If]#If[/URL] Win64 Then
Sheet11.Range("Win_64_32") = 64
[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=ElseIf][URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=Else]#Else[/URL] If[/URL] Not Win64 Then
Sheet11.Range("Win_64_32") = 32
[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=End]#End[/URL] If
[/FONT]
[FONT="Times New Roman"] If Not Sheet11.Range("F80") Then
UserForm7.Show
Else
Application.StatusBar = "Solver Reference already available"
End If
End Sub
There is some unnecessary code here but I also check for 32/b4bit version for other uses.
Code to load solver reference (BUT LOCATION IS CURRENTLY HARD CODED a F92 or F93)
Code:
Private Sub CommandButton1_Click()
[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=If]#If[/URL] VBA7 And Win64 Then
Sheet11.Range("Win_64_32") = 64
wintype = Sheet11.Range("F92")
ThisWorkbook.VBProject.References.AddFromFile wintype
Application.StatusBar = "Solver Reference was added"
Sheet11.Range("F80") = True
[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=Else]#Else[/URL]
Sheet11.Range("Win_64_32") = 32
wintype = Sheet11.Range("F93")
ThisWorkbook.VBProject.References.AddFromFile wintype
Application.StatusBar = "Solver Reference was added"
[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=End]#End[/URL] If
UserForm7.Hide
'Calculate
'Application.Wait (Now + TimeValue("00:00:10"))
DoEvents
Application.ActiveWorkbook.Save
End Sub