在 VBA 中创建对象 DLL(C#)

Creating object DLL(C#) in VBA

提问人:gregor 提问时间:9/25/2023 更新时间:9/25/2023 访问量:29

问:

我已经在 C# 中创建了 dll 和 tlb 文件以在 VBA 中使用它。 dll 的代码如下所示:

using ModulPlanista.ServiceReference1;
using System;
using System.Collections.Generic;
using System.Linq;

namespace ModulPlanista
{
    public class PlanistaMod
    {
        IiPlanistaServiceClient Planista;
        public bool ZaladowanoUsluge = false;
        List<UserViewUser> user = new List<UserViewUser>();
        EventsListRepsonse ListaEventow;
        long userID = 0;
        public int blad = 0;

        public PlanistaMod(string UserName)
        {
            try
            {
                Planista = new IiPlanistaServiceClient();
            }
            catch
            { 
                Planista = null;
                blad = -1;
                return;
            }
            try
            {
                user.AddRange(Planista.GetUsers(UserName));
                userID = GetUserID(UserName);
            }
            catch
            {
                user = new List<UserViewUser>();
                Planista = null;
                blad = -2;
                return;
            }
            try
            {
                ListaEventow = Planista.GetEventsList();
            }
            catch 
            {
                user = new List<UserViewUser>();
                Planista = null;
                blad = -3;
                return;
            }
            ZaladowanoUsluge = true;
        }       

        public string GetManufNumber(string UID)
        {
            return Planista.GetWoNoByUID(UID);
        }

    }
}

在C#中,我使用dll,如下所示:

using ModulPlanista;
namespace nPlanista
{
   public string GetManufacturerNo()
   {
        PlanistaMod module = new PlanistaMod(login);
        string manufacturerNo=planistaModule.GetManufNumber("1007177718");
   }
}

我在创建对象PlanistaMod时遇到问题,它在VBA中不可见。我只能看到对 Web 服务 (ModulPlanista.ServiceReference1) 的引用,如下图所示,在此处输入图像描述

知道如何使用dll吗?

C# VBA 对象 DLL

评论

1赞 JonasH 9/25/2023
我认为 VBA 会使用 COM 进行互操作。我相当确定它不能使用常规的 .net 类型,因为它不是 .net 语言。请参阅向 COM 公开 .NET 组件
0赞 JohnM 9/25/2023
不绝对确定这是您所要求的,但如果您尝试使用 COM 互操作从 VBA 调用 C# 代码,请参阅从 VBA 调用 C# 代码(COM 互操作)(为清楚起见,链接指向我的网站)
0赞 gregor 9/27/2023
约翰·我已经从您的网站创建了dll,接下来我使用RegAsm工具“注册COM互操作”,我有tlb文件,接下来我添加了对VBA的引用。但是在“Set oMyStuff = New BlogProject.MyStuff”一行中,我得到了错误:运行时错误(80070002),自动化错误。

答: 暂无答案