/// <summary> /// Executes a procedure inside a standard module in a VBA project /// </summary> /// <param name="name">the name of the procedure to invoke</param> /// <param name="args">arguments to pass to the procedure</param> /// <remarks>the returned object can be a COM object, and the callee is responsible for releasing it appropriately</remarks> /// <returns>an object representing the return value from the procedure, or null if none.</returns> public object StdModExecute(string name, object[] args = null) { // We search for the dispId using the real type info rather than using staticModule.GetIdsOfNames, // as we can then also include PRIVATE scoped procedures. var func = _parent.Funcs.Find(name, PROCKIND.PROCKIND_PROC); if (func == null) { throw new ArgumentException($"StdModExecute failed. Couldn't find procedure named '{name}'"); } var staticModule = GetStdModAccessor(); try { return(IDispatchHelper.Invoke(staticModule, func.FuncDesc.memid, IDispatchHelper.InvokeKind.DISPATCH_METHOD, args)); } finally { RdMarshal.ReleaseComObject(staticModule); } }