<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Execute SAS Program via VBA ('LibGit2Sharp.Core.NativeMethods' threw an exception) in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Execute-SAS-Program-via-VBA-LibGit2Sharp-Core-NativeMethods/m-p/341435#M22616</link>
    <description>&lt;P&gt;I am using SAS Enterprise Guide 7.12 HF3 (7.100.2.3444) (64-bit)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I&amp;nbsp;have a SAS file called CalculateLoad.egp which just imports some CSV files,&amp;nbsp;grabs some&amp;nbsp;data from a Windows SQL Server, does a few calculations and&amp;nbsp;spits out a CSV file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wanted to run CalculateLoad.egp several times via automation. I wanted to use Excel VBA to let the user run the CalculateLoad.egp many many times.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have been following this document (&lt;A href="http://support.sas.com/resources/papers/proceedings12/298-2012.pdf" target="_blank"&gt;http://support.sas.com/resources/papers/proceedings12/298-2012.pdf&lt;/A&gt;) that tells me how to use Excel VBA to automate a SAS Program.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For reference, the relevant VBA code is below (its on Page 6 of the document):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Option Explicit ' Forces us to declare all variables&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Dim Application ' Application &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Dim Project ' Project object &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Dim sasProgram ' Code object (SAS program) &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Dim n ' counter &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Set Application = CreateObject("SASEGObjectModel.Application.4.3") &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;' Set to your metadata profile name, or "Null Provider" for just Local server &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Application.SetActiveProfile("My Server") &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;' Create a new Project &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Set Project = Application.New ' add a new code object to the Project &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Set sasProgram = Project.CodeCollection.Add&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code I am trying to write&amp;nbsp;is as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Public Application&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;Public Project&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;Public sasProgram&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Sub Example2()&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set Application = CreateObject("SASEGObjectModel.Application.7.1")&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set Project = Application.New&amp;nbsp;&amp;nbsp; ' &amp;lt;&amp;lt;&amp;lt;&amp;lt;------- ERROR OCCURING HERE&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;End sub&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The error message I am getting is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Run-time error '-2146233036 (80131534)': The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I also get this error if I try: &lt;FONT face="courier new,courier"&gt;Set Project = Application.Open("c:\myprojects\project.egp", "")&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would appreciate some guidance.... Thanks....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Some additional background information (just in case it is relevant):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When SAS was first installed I couldn't even execute: &lt;FONT face="courier new,courier"&gt;Set Application = CreateObject("SASEGObjectModel.Application.7.1")&lt;/FONT&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I got the following error message from VBA:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Run-time error '429': ActiveX component can't create object&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;From Googling, I&amp;nbsp;ran the following from command prompt:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;RegASM.exe /tlb:SASEGScripting.tlb /codebase “C:\Program Files\SASHome94M3\SASEnterpriseGuide\7.1\SASEGScripting.dll&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and then&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;RegTypeLib.exe “C:\Program Files\SASHome94M3\SASEnterpriseGuide\7.1\SASEGScripting.tlb”&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So now VBA happliy executes &lt;FONT face="Courier New"&gt;Set Application = CreateObject("SASEGObjectModel.Application.7.1")&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But it doesn't like &lt;FONT face="Courier New"&gt;Set Project = Application.New&amp;nbsp;&lt;/FONT&gt;or &lt;FONT face="Courier New"&gt;Set Project = Application.Open("c:\myprojects\project.egp", "")&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Would appreciate it if someone knows how to fix it. Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 16 Mar 2017 06:25:14 GMT</pubDate>
    <dc:creator>_Asdfghjkl</dc:creator>
    <dc:date>2017-03-16T06:25:14Z</dc:date>
    <item>
      <title>Execute SAS Program via VBA ('LibGit2Sharp.Core.NativeMethods' threw an exception)</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Execute-SAS-Program-via-VBA-LibGit2Sharp-Core-NativeMethods/m-p/341435#M22616</link>
      <description>&lt;P&gt;I am using SAS Enterprise Guide 7.12 HF3 (7.100.2.3444) (64-bit)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I&amp;nbsp;have a SAS file called CalculateLoad.egp which just imports some CSV files,&amp;nbsp;grabs some&amp;nbsp;data from a Windows SQL Server, does a few calculations and&amp;nbsp;spits out a CSV file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wanted to run CalculateLoad.egp several times via automation. I wanted to use Excel VBA to let the user run the CalculateLoad.egp many many times.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have been following this document (&lt;A href="http://support.sas.com/resources/papers/proceedings12/298-2012.pdf" target="_blank"&gt;http://support.sas.com/resources/papers/proceedings12/298-2012.pdf&lt;/A&gt;) that tells me how to use Excel VBA to automate a SAS Program.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For reference, the relevant VBA code is below (its on Page 6 of the document):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Option Explicit ' Forces us to declare all variables&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Dim Application ' Application &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Dim Project ' Project object &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Dim sasProgram ' Code object (SAS program) &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Dim n ' counter &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Set Application = CreateObject("SASEGObjectModel.Application.4.3") &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;' Set to your metadata profile name, or "Null Provider" for just Local server &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Application.SetActiveProfile("My Server") &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;' Create a new Project &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Set Project = Application.New ' add a new code object to the Project &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Set sasProgram = Project.CodeCollection.Add&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code I am trying to write&amp;nbsp;is as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Public Application&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;Public Project&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;Public sasProgram&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Sub Example2()&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set Application = CreateObject("SASEGObjectModel.Application.7.1")&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set Project = Application.New&amp;nbsp;&amp;nbsp; ' &amp;lt;&amp;lt;&amp;lt;&amp;lt;------- ERROR OCCURING HERE&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;End sub&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The error message I am getting is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Run-time error '-2146233036 (80131534)': The type initializer for 'LibGit2Sharp.Core.NativeMethods' threw an exception.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I also get this error if I try: &lt;FONT face="courier new,courier"&gt;Set Project = Application.Open("c:\myprojects\project.egp", "")&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would appreciate some guidance.... Thanks....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Some additional background information (just in case it is relevant):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When SAS was first installed I couldn't even execute: &lt;FONT face="courier new,courier"&gt;Set Application = CreateObject("SASEGObjectModel.Application.7.1")&lt;/FONT&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I got the following error message from VBA:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Run-time error '429': ActiveX component can't create object&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;From Googling, I&amp;nbsp;ran the following from command prompt:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;RegASM.exe /tlb:SASEGScripting.tlb /codebase “C:\Program Files\SASHome94M3\SASEnterpriseGuide\7.1\SASEGScripting.dll&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and then&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;RegTypeLib.exe “C:\Program Files\SASHome94M3\SASEnterpriseGuide\7.1\SASEGScripting.tlb”&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So now VBA happliy executes &lt;FONT face="Courier New"&gt;Set Application = CreateObject("SASEGObjectModel.Application.7.1")&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But it doesn't like &lt;FONT face="Courier New"&gt;Set Project = Application.New&amp;nbsp;&lt;/FONT&gt;or &lt;FONT face="Courier New"&gt;Set Project = Application.Open("c:\myprojects\project.egp", "")&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Would appreciate it if someone knows how to fix it. Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2017 06:25:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Execute-SAS-Program-via-VBA-LibGit2Sharp-Core-NativeMethods/m-p/341435#M22616</guid>
      <dc:creator>_Asdfghjkl</dc:creator>
      <dc:date>2017-03-16T06:25:14Z</dc:date>
    </item>
    <item>
      <title>Re: Execute SAS Program via VBA ('LibGit2Sharp.Core.NativeMethods' threw an exception)</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Execute-SAS-Program-via-VBA-LibGit2Sharp-Core-NativeMethods/m-p/341545#M22618</link>
      <description>&lt;P&gt;I'm afraid that the exception is caused by using 32-bit Excel to automate a 64-bit version of SAS Enterprise Guide. &amp;nbsp;I think that the Git integration with EG (LibGit2Sharp) is specific to the bit architecture, so you have to drive this from a 64-bit process&amp;nbsp;&lt;STRONG&gt;or&lt;/STRONG&gt; install a 32-bit version of SAS Enterprise Guide. &amp;nbsp;Someone like&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15089"&gt;@CaseySmith&lt;/a&gt;&amp;nbsp;might be able to confirm.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2017 12:12:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Execute-SAS-Program-via-VBA-LibGit2Sharp-Core-NativeMethods/m-p/341545#M22618</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2017-03-16T12:12:05Z</dc:date>
    </item>
    <item>
      <title>Re: Execute SAS Program via VBA ('LibGit2Sharp.Core.NativeMethods' threw an exception)</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Execute-SAS-Program-via-VBA-LibGit2Sharp-Core-NativeMethods/m-p/341657#M22624</link>
      <description>&lt;P&gt;Chris is correct.&amp;nbsp; The libgit2&amp;nbsp;library (git2-e0902fb.dll)&amp;nbsp;(which&amp;nbsp;EG accesses via LibGit2Sharp)&amp;nbsp;is specific to the bit architecture.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you disable EG's Program History feature (uncheck "Enable program history" in Tools-&amp;gt;Options-&amp;gt;Program History), you&amp;nbsp;should get further, since the library is not immediately loaded in that case.&amp;nbsp; However, if you do any operations that result in EG attempting to use the library, you'll see the exception again.&amp;nbsp; (For example, I noticed simply opening a saved project causes the library to get loaded even if the Program History feature is off.)&amp;nbsp; Otherwise, I second Chris' suggested workarounds.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2017 16:21:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Execute-SAS-Program-via-VBA-LibGit2Sharp-Core-NativeMethods/m-p/341657#M22624</guid>
      <dc:creator>CaseySmith</dc:creator>
      <dc:date>2017-03-16T16:21:13Z</dc:date>
    </item>
  </channel>
</rss>

