Install Solver Add-In through VBA

  • Hi,


    I was wondering if there is a way of adding any Excel Add-Ins automatically when a worksheet is opened. For e.g. If someone opens a worksheet on any computer it automatically adds the Solver Addin if it is already not there.


    Thanks.

  • The answer to your question is yes... providing that the machine can 'see' the add-in (i.e. on the hard drive or a network that the PC has access to)...


    If it's where all the other add-ins are you can use the following code


    Code
    Private Sub Workbook_Open() 
    'you need to put this in the "ThisWorkBook" module. 
    
    
    Set Solv = AddIns("Solver Add-In") 
    If Solv.Installed = False Then 
    AddIns("Solver Add-in").Installed = True 
    End If 
    End Sub
  • Anuja ??


    WillR's answer is correct except that he has it working through the Workbook Open event.


    From your Question I understand that you want it to work with a specific sheet selection ?? within a workbook.


    If this is the case then use the following code as per attached example file.



    Private Sub Worksheet_Activate()
    On Error GoTo Error
    Set Solv = AddIns("Solver Add-In")
    If Solv.Installed = False Then
    AddIns("Solver Add-in").Installed = True
    End If
    Exit Sub
    Error:
    Exit Sub
    End Sub


    Private Sub Worksheet_Deactivate()
    On Error GoTo Error
    Set Solv = AddIns("Solver Add-In")
    If Solv.Installed = True Then
    AddIns("Solver Add-in").Installed = False
    'This shuts solver to conserve memory
    Workbooks("Solver.XLA").Close SaveChanges:=False
    End If
    Exit Sub
    Error:
    Exit Sub
    End Sub


    Regards


    AJW

  • Hi WillR
    Thanks for your code. It has solved the problem.


    Quote

    Originally posted by WillR
    The answer to your question is yes... providing that the machine can 'see' the add-in (i.e. on the hard drive or a network that the PC has access to)...


    If it's where all the other add-ins are you can use the following code


    Code
    Private Sub Workbook_Open() 
    'you need to put this in the "ThisWorkBook" module. 
    
    
    Set Solv = AddIns("Solver Add-In") 
    If Solv.Installed = False Then 
    AddIns("Solver Add-in").Installed = True 
    End If 
    End Sub
  • Hi AJW,
    Thanks for your code.


Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!