• 228 views | 3 messages Discussion: LEAP
    Topic: LEAP API Error in Excel VBASubscribe | Previous | Next
  • Jiefeng Kang 4/28/2021

    Hi guys,

    I followed the guidance of using LEAP API in Excel VBA editor and an error happened.

    Here is what I did and what happend:
    Open Excel, create a new blank workbook, then open Visual Basic Editor by "Alt + F11".
    Then go to Tools: References of VB editor and scroll down to find "LEAP API" and check the box of it. In fact, the guidance says I should check the "LEAP", but I can only find a "LEAP API" here:



    Go to View: Immediate Window to open the "Immediate" window.
    Then I started coding at the Immediate window, once at a time:
    code: Set L = createobject("LEAP.LEAPApplication")
    press Enter key and seems nothing happen;
    code: ? L.Areas.Count
    hit Enter key and here the error happened; it says:
    "Run-time error '-2147418113 (8000ffff)':
    Access violation at address 0000000001A3CA2B in module 'leap.exe'.
    Read of address 00000000000000F0"

    I wonder how can I fix it?

    I am fresh to VBA language, but used Macro function sometimes in Excel before.
    Thank you for your time : )

    P.S. And how can I adjust the size of the picture in this post, it seems too large ...
  • Charlie Heaps 4/29/2021
      Best Response

    2 Likes

    Please post pictures as attachments - not inline.

    Below is some sample code in Visual Basic for Applications (VBA) showing how to start up and shut down LEAP (e.g. from within an Excel Macro).

      Dim L As Object
      On Error Resume Next

      'Startup
      'Try to connect to an existing running copy of LEAP (note the leading comma!)
      Set L = GetObject("", "LEAP.LEAPApplication")
      'Or if there is no existing running copy, create a new instance of LEAP
      If L Is Nothing Then
      Set L = CreateObject("LEAP.LEAPApplication")
      End If

      'Ensure LEAP is fully started up
      While (Not L.ProgramStarted)
      Application.Wait (Now + TimeValue("0:00:01"))
      Wend
      L.Visible = True 'Make LEAP visible
      MsgBox(L.ActiveArea.Name) 'Do something with LEAP such as showing name of area

      'Shutdown
      'First check to see if it is ready for shutdown (CanQuit).
      'If there are unsaved changes this will prompt you to save
      'Returns false if you cancel that dialog or if a supporting screen (regions, fuels etc.) is open.
      'You can also use LEAP.SaveArea to save the current area first
      If LL.CanQuit Then
      Set LL = Nothing 'Exits LEAP and removes its icon from the Windows Taskbar
      End If
  • Jiefeng Kang 5/2/2021
      Best Response

    Hi Mr. Heaps,
    Thank you again for your help.
    I tried your code, sometimes it works but sometimes not. I am going to learn some more about VBA before go back to this issue.
    P.S. Sorry for the picture inline, hope I can fix it but seems I can't do that.