• 166 views | 4 messages Discussion: LEAP
    Topic: Problem using variables in LEAP objects in ExcelSubscribe | Previous | Next
  • Gregers Larsen 1/19/2016

    511 Views

    I have a huge problem with the LEAP API in Excel, whit no solution in sight. It's a general problem, by I'll explain it by using the example code below

    ---------------

    'Option Explicit

    Dim Fuel_counter As Integer
    Dim scenario_counter As Integer
    Dim area_name As String
    Dim scenario_name As String
    Dim fuel_name As String

    Sub LEAP_Extractor()

    Set L = CreateObject("LEAP.LEAPApplication") 'Opens LEAP and sets "L" to use objects for

    area_name = Range("A3").Value

    Worksheets("Energy Demands").Cells(1, 1) = area_name

    L.ActiveArea = area_name ' Set ActiveArea to area_name DOESN'T WORK!!!???
    L.Calculate (False) 'Calculates the LEAP Area and sets the viewing pane to "Results"

    End Sub

    --------------

    I want the ability for the user to choose, and use Excel lists, for variables. Doing this in VBA you input a reference to a cell or range for the code to read.

    In the above sample code, I do this with area_name, it could have been scenarios, branches, etc. All good. Now I want LEAP objects (in this case ActiveArea) to read it in my Sub.

    No dice, LEAP error: "LEAP.ActiveArea: Cannot set active area to nothing". Cannot do "area_name" in the VBA, because then LEAP thinks the name is area_name, which yields another error...

    Again, this error is for all "ActiveXxxx" variables. How can I set variables if I cannot reference them, or have I missed something?

    For various reasons, I have no interest in using LEAPs script editor, opting rather for VBA. I think the problem persists there too, what I can tell.


    Hope you can help,


    Gregers
  • Taylor Binnington 1/19/2016
      Best Response

    510 Views

    Gregers,

    You are free to use any Windows scripting language that you like - no need to use the built-in editor.

    I'm able to run your script without a problem on my version of Excel. A simple question, though: what is in cell A3? Is it empty? It must contain a string corresponding to a LEAP area, i.e. a LEAP area which appears in the list when you select Area: Open from LEAP's main menu.

    Which Excel WorkSheet is active when you make the area name assignment from cell A3?

    Taylor
  • Gregers Larsen 1/19/2016
      Best Response

    494 Views

    Seems I did something stupid in the Excel file (not VBA), that I had deleted the area. I'm sorry for the trouble.

    I have another question, related to controlling the result tables. I have found the object Branch.Level, but it is read-only. Is there a way to control the level in the result tables?

    I have tried seeing if I could use Fuel.Name = "Electricity" for defining fuel in the result tables, but so far, no luck,. Seems I cannot use it for this purpose, but I cannot find an ActiveFuel variable. Is there any way to specify fuel in results view?

    Using the VBA "Set L = CreateObject("LEAP.LEAPApplication")" works, but only if LEAP is already running. LEAP fails to open if it not already is. Can I do something to help it?

    Other than these issues I have finished my VBA extraction tool and will release it here when I have it working.


    Gregers
  • Taylor Binnington 1/20/2016
      Best Response

    485 Views

    Hi Gregers,

    Regarding your Branch.Level question, you've seen by (brief) reply here, right?


    To export specific results view, have you thought about creating favorites for them? Depending on what you'd like to achieve, this might be more appropriate. Have a look at this thread:


    Alternatively, you might try iterating through years and printing the output of:

    LEAP.Variable("result variable name").Value(year, unit name, filter)

    You can find additional help on the use of the Value property of Variable in the help menu which is attached to the script editor. You may use the filter to control the fuel: for example, "Fuel=Electricity".

    I'm still looking into the CreateObject problem.

    Hope this helps,
    Taylor