• 85 views | 2 messages Discussion: LEAP
    Topic: Using LEAP API in ExcelSubscribe | Previous | Next
  • Gregers Larsen 1/6/2016

    547 Views

    Hello. I am trying to extract result data from LEAP into Excel using the LEAP API in Excel VBA. For various reasons, I cannot use the inbuilt script editor.

    I have some trouble getting started. I am trying to follow the guide at http://www.energycommunity.org/WebHelpPro/API/Exploring.htm, but all I get for my troubles are errors.

    I have added the "LEAP API" object in References in VBA tools, successfully ran "Set L = createobject("LEAP.LEAPApplication")" for working with LEAP objects in the immediate window.

    However, I am running into trouble as soon as I try to set LEAP to the Analysis view (L.View = "Analysis"), getting the error: "Run-time error 348: Object doesn't support this property or method".

    I have another error for when I am trying to make LEAP calculate. Trying L.Calculate creates an "Error 450: Wrong number of arguments or invalid property assignment". Calculate in the Objects library is set as a Sub, which I do not understand the implication of.

    I am new to using Objects this way in VBA and have no Google (China), so does anyone have experience in this?


    - Gregers

  • Taylor Binnington 1/8/2016
      Best Response

    544 Views

    Hi Gregers,

    To change the LEAP view, the proper syntax is

    L.ActiveView = "Analysis"

    The Calculate method of the LEAP object requires an argument, True or False (indicating whether WEAP will also be calculated, for linked LEAP/WEAP models). So you could either enter:

    L.Calculate(False)

    or

    L.ForceRecalculation
    L.ActiveView = "Results"

    Even if you're working outside LEAP's script editor, it's often useful to have the editor open beside you to use as a reference for the API methods and properties. This will also be the most up-to-date source of API documentation.

    Hope this help,
    Taylor