+ Reply to Thread
Results 1 to 3 of 3

Macro/Solver error message question

  1. #1

    Macro/Solver error message question

    Hi, I am using Excel97. I recorded a very simple macro involving
    Solver. When running this recorded macro I get an error message:

    Compile error
    Sub or function not defined

    Apparently the offending statement is SolverOK, which is the first
    statement in the sub.

    Since Excel itself recorded the macro, I don't know what to do about
    this. Any help or ideas?

    Many thanks in advance.


  2. #2
    Tom Ogilvy
    Guest

    RE: Macro/Solver error message question

    You have to set a reference to solver before you execute those statements.

    http://support.microsoft.com/default...b;en-us;843304
    How to create Visual Basic macros by using Excel Solver in Excel 97


    If doing it locally, you can do it manually. If you will be distributing
    it, Dana Delouise posted this code in the past:

    Sub SolverInstall()
    '// Dana DeLouis
    Dim wb As Workbook

    On Error Resume Next
    ' Set a Reference to the workbook that will hold Solver
    Set wb = ActiveWorkbook

    With wb.VBProject.References
    .Remove .Item("SOLVER")
    End With

    With AddIns("Solver Add-In")
    .Installed = False
    .Installed = True
    wb.VBProject.References.AddFromFile .FullName
    End With
    End Sub

    --
    Regards,
    Tom Ogilvy



    "[email protected]" wrote:

    > Hi, I am using Excel97. I recorded a very simple macro involving
    > Solver. When running this recorded macro I get an error message:
    >
    > Compile error
    > Sub or function not defined
    >
    > Apparently the offending statement is SolverOK, which is the first
    > statement in the sub.
    >
    > Since Excel itself recorded the macro, I don't know what to do about
    > this. Any help or ideas?
    >
    > Many thanks in advance.
    >
    >


  3. #3

    Re: Macro/Solver error message question


    Tom Ogilvy wrote:
    > You have to set a reference to solver before you execute those statements.
    >
    > http://support.microsoft.com/default...b;en-us;843304
    > How to create Visual Basic macros by using Excel Solver in Excel 97
    >
    >
    > If doing it locally, you can do it manually. If you will be distributing
    > it, Dana Delouise posted this code in the past:
    >
    > Sub SolverInstall()
    > '// Dana DeLouis
    > Dim wb As Workbook
    >
    > On Error Resume Next
    > ' Set a Reference to the workbook that will hold Solver
    > Set wb = ActiveWorkbook
    >
    > With wb.VBProject.References
    > .Remove .Item("SOLVER")
    > End With
    >
    > With AddIns("Solver Add-In")
    > .Installed = False
    > .Installed = True
    > wb.VBProject.References.AddFromFile .FullName
    > End With
    > End Sub
    >
    > --
    > Regards,
    > Tom Ogilvy
    >

    Very helpful, Tom, I really appreciate it.


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1