使用 Application.Run VBA "The macro may not be available in this workbook or all macros may be disabled." 调用自定义函数时出现 BERT 错误

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."

我实际上是在使用 VSTO c# 构建一个使用 BERT 的插件,它有一个桥接器可以在 excel 上获取自定义 R 函数。但是我在尝试使用 VBA

中的 Application.Run 调用 Bert 函数目录上的自定义函数时遇到一些错误

其实我有 ThisAddin class:

    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;
    }

在另一个名为 BertCalls 的 class 中,我有以下代码

    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");

    }

如您所见,我正在使用一些自定义验证 classes.

实际上,当我调用内置 R 函数时它工作正常,例如 "sum" 但是当我尝试调用自定义函数时,我在执行方法 "Can't execute the macro or it is disabled"[=15 时出现编译错误=]

我做了以下事情:

我需要使用带有 VBA 的 BERT 执行自定义函数,但我遇到了这个错误,而且我没有找到任何可以避免这个错误的方法。

感谢您的帮助

问题已解决!

我正在使用 windows 10,在 BERT2 和自定义 R 起作用的 onedrive/documents 地毯路线中,我不得不在本地文件地毯 C:\Users\user\Documents 中复制该地毯它适用于上面的确切代码。

如果你需要在 windows 10 中使用文档路由,请注意路由。OneDrive/Documents != User/Documents