Option Explicit
Private Sub Workbook_Open()
FindSolverexcel
End Sub
Option Explicit
Sub FindSolverexcel()
On Error Resume Next
With Application.FileSearch
.NewSearch
.SearchSubFolders = True
.Filename = "Solver.xla"
.LookIn = Application.Path
.Execute
If .Execute > 0 Then
If AddIns("Solver Add-in").Installed = False Then
AddIns("Solver Add-in").Installed = True
If Err.Number > 0 Then
If Err.Number = 1004 Then
MsgBox "Please check if your security setting do not allow you to use VBProject" _
& vbCr & "Click Tools, Macro, security" & vbCr _
& "trusted source check access to Visual Basic Project" & vbCr & "close and open the file again" _
& vbCr & "if there is no option then proceed"
Err.Clear
Exit Sub
Else
AddIns.Add(.FoundFiles(1)).Installed = True
Err.Clear
End If
End If
CreateObject("WScript.Shell").Popup "Solver successfully installed", 1, "Solver"
End If
Else
MsgBox "Solver Not Installed In this Computer", vbCritical
Exit Sub
End If
End With
Dim i As Integer, x As Long
x = ThisWorkbook.VBProject.References.Count
For i = 1 To x
If ThisWorkbook.VBProject.References(i).Name = "SOLVER" Then
CreateObject("WScript.Shell").Popup "Reference aleady set", 1, "Solver"
Exit Sub
End If
Next i
ThisWorkbook.VBProject.References.AddFromFile Application.LibraryPath _
& Application.PathSeparator & "SOLVER" & Application.PathSeparator & "SOLVER.XLA"
CreateObject("WScript.Shell").Popup "Reference successfully installed", 1, "Solver"
Application.Run "Solver.xla!auto_open"
End Sub
|