title: BERT error while calling a custom function with Application.Run VBA "The macro may not be available in this workbook or all macros may be disabled."
body: <p>I'm actually using VSTO c# to build an Addin that uses BERT has a bridge to get custom R functions on excel. But Im getting some errors trying to call custom functions on Bert functions directory using Application.Run in VBA</p>
  
  <p>Actually I have on ThisAddin class:</p>
  
  <pre><code>    private void ThisAddIn_Startup(object sender, System.EventArgs e)
      {
      }
  
      private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
      {
      }
  
      void InternalStartup()
      {
      }
  
      public void BertCall(string functionName, String dataRange)
      {
          if(dataRange.Equals("00:00"))
          {
              MessageBox.Show("Blank cells were found, pleace fill it and try again");
          }
          else
          {
              double result = Application.Run("BERT.Call", functionName, getCurrentWorkSheet().Range[dataRange]);
              MessageBox.Show(result.ToString());
          }
      }
  
      private Worksheet getCurrentWorkSheet()
      {
          Worksheet currentWorksheet = Globals.Factory.GetVstoObject(
          this.Application.ActiveWorkbook.Worksheets[1]);
          return currentWorksheet;
      }
  </code></pre>
  
  <p>And in another class Called BertCalls I have the following code</p>
  
  <pre><code>    Validations validate = new Validations();
  
      public void bertCalls(string functionName)
      {
          Globals.ThisAddIn.BertCall(functionName, validate.getRange()); //this method calls ThisAddIn BertCall method, that handles the comunication with Bert
      }
  
      public void Sumar()
  
      {
          Excel.Range selectedRange = Globals.ThisAddIn.Application.Selection;
          bertCalls("sum");
  
      }
  </code></pre>
  
  <p>As you see Im using some custom validation classes.</p>
  
  <p>Actually it is working fine when I call build-in R functions, like "sum" but when I try to call custom functions I had the compile error while excecuting the method "Can't execute the macro or it is disabled"</p>
  
  <p>I did the following things:</p>
  
  <ul>
  <li>Create the functions on Documents/Bert2/functions</li>
  <li>Tried to call by the name of the custom function using BERT.Call paramether, but does not work.</li>
  <li>Enabling Trust center to VBA applications and macros</li>
  <li>Change the Application.Run param same as in BERT documentation to 
  <strong><em>Application.Run(functionName, getCurrentWorkSheet().Range[dataRange]);</em></strong> where functionName is the name of the customFunction, and called by R.AddTest, but get a big negative number.</li>
  </ul>
  
  <p>I need to execute custom functions using BERT with VBA, but I'm getting this error, and I did not find nothing to avoid this error.</p>
  
  <p>Thanks for the help</p>