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
    1. Private Sub Workbook_Open()
    2. 'you need to put this in the "ThisWorkBook" module.
    3. Set Solv = AddIns("Solver Add-In")
    4. If Solv.Installed = False Then
    5. AddIns("Solver Add-in").Installed = True
    6. End If
    7. 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
    1. Private Sub Workbook_Open()
    2. 'you need to put this in the "ThisWorkBook" module.
    3. Set Solv = AddIns("Solver Add-In")
    4. If Solv.Installed = False Then
    5. AddIns("Solver Add-in").Installed = True
    6. End If
    7. End Sub
  • Hi AJW,
    Thanks for your code.