如何使用 Excel 设置 COM 服务器接口?

发布于 2024-11-17 14:07:52 字数 2476 浏览 1 评论 0原文

版本
Excel 2003
Windows XP
SimaPro 7.3.0 开发版
使用工作计算机,但在此计算机上设置为管理员
Excel/VBA 中引用的库: Visual Basic for Applications; Microsoft Excel 11.0 对象库; OLE自动化; Microsoft Office 11.0 对象库; Microsoft Forms 2.0 对象库; COM+ 1.0 管理类型库; COM MakeCab 1.0 类型库; COM+ 服务类型库; SimaPro 库
我:初学者

我想要做什么 我正在使用一个名为 SimaPro 的程序,它存储“生命周期分析”信息的数据库。该程序内置了 COM 接口功能。该程序声明它确实支持 Excel/VBA(但没有指定版本)。

我正在尝试将此程序和/或 COM 服务器连接到 excel,以便我可以通过 excel 与信息进行交互。

我做了什么
我已经完成了他们列出的程序:
-打开 SimaPro
-注册COM服务器
-然后我将以下代码粘贴到 VBA 中并尝试运行它。这段代码是软件公司提供的示例代码,我只编辑了SP.Server、SP.Alias、SP.Login和SP.OpenProject字段(下面是编辑后的)。

发生了什么
运行时错误:“-2147418113 (8000ffff)”:
自动化错误
灾难性的失败

问题
-服务器名称正确吗?我已经阅读了一些关于 COM 服务器的内容,但我不知道我放入它的方式是否采用正确的“形式”
-这是否与某些已注册/未注册的 DLL 有关?我曾与公司的 IT 人员和软件程序员一起工作。他们都不太熟悉 COM,但有人指出 DLL 可能是问题所在。

感谢您的帮助!!

这是我输入的代码:

Sub CreateProcess()
Dim SP As SimaProServer
Dim PC As Process
Dim PC2 As Process
Dim PL As ProcessLine
Dim Param As ParamLine
Dim Subs As Substance
Set SP = New SimaProServer
SP.Server = "Local Server"
SP.Alias = "C:\Documents and Settings\All Users\Documents\SimaPro\Database\"
SP.Database = "Professional"
SP.OpenDatabase
SP.Login "", ""
SP.OpenProject "PROJECT", ""
' Not project's actual name, not allowed to state name of project
SP.CreateSubstance "Air", Subs
Subs.CASNumber = "4-5-13"
Subs.Name = "Some substance"
Subs.DefaultUnit = "kg"
Subs.Update
SP.CreateProcess ptMaterial, PC
Set PL = PC.AddLine(ppProduct, -1)
PL.ObjectName = "Steel 2"
PL.UnitName = "kg"
PL.Amount = "2"
PL.Comment.Add ("My new created process")
PL.CategoryPath = "Chemicals\inorganic"
PC.Update
' create second material process Case
SP.CreateProcess ptMaterial, PC2
Set PL = PC2.AddLine(ppProducts, 0)
PL.ObjectName = "Case 2"
PL.UnitName = "kg"
PL.Amount = "10"
Set Param = PC2.AddParamLine(ptInputParameter, -1)
Param.Name = "A"
Param.Value = "2,3"
' add input from Steel
Set PL = PC2.AddLine(ppMaterialsFuels, -1)
' input from steel
PL.SetProduct "Introduction to SimaPro 7", ptMaterial, "Steel 2"
PL.Amount = "8"
PL.UnitName = "kg"
Set PL = PC2.AddLine(ppAirborneEmissions, -1)
' input from steel
PL.SetSubstance "Some substance", ""
PL.Amount = "A+1"
PL.UnitName = "kg"
PC2.Update
SP.Logout
SP.CloseDatabase
Set SP = Nothing
End Sub

Versions
Excel 2003
Windows XP
SimaPro 7.3.0 Developer Version
Using a Work computer but was made administrator on this machine
Libraries referenced in Excel/VBA: Visual Basic for Applications; Microsoft Excel 11.0 Object Library; OLE Automation; Microsoft Office 11.0 Object Library; Microsoft Forms 2.0 Object Library; COM+ 1.0 Admin Type Library; COM MakeCab 1.0 Type Library; COM+ Services Type Library; SimaPro Library
Me: Beginner

What I'm trying to do
I am using a program called SimaPro that stores databases of "Life Cycle Analysis" information. The program has built in COM interface functionality. The program states that it does, indeed support Excel/VBA (but it doesn't specify versions).

I am trying to connect this program and/or COM server to excel so that I can interact with the information through excel.

What I've done

I've done the procedure they list:

-Open SimaPro

-Register COM Server

-Then I pasted the below code into VBA and tried to run it. This code is the sample code provided by the software company, I edited only the SP.Server, SP.Alias, SP.Login, and SP.OpenProject fields (below is as edited).


What Happened
Run-time Error: '-2147418113 (8000ffff)':
Automation Error

Catastrophic Failure

Question(s)

-Is the server name right? I've been reading a little on COM servers and I don't know if the way I put it in is in the right "form"

-Could it have something to do with certain registered/unregistered DLLs? I've worked with the company's IT people, and software programmers. None of them were very familiar with COM but one person suggested the DLLs might be the issue.

Thanks for your help!!

Here is the code that I'm inputting:

Sub CreateProcess()
Dim SP As SimaProServer
Dim PC As Process
Dim PC2 As Process
Dim PL As ProcessLine
Dim Param As ParamLine
Dim Subs As Substance
Set SP = New SimaProServer
SP.Server = "Local Server"
SP.Alias = "C:\Documents and Settings\All Users\Documents\SimaPro\Database\"
SP.Database = "Professional"
SP.OpenDatabase
SP.Login "", ""
SP.OpenProject "PROJECT", ""
' Not project's actual name, not allowed to state name of project
SP.CreateSubstance "Air", Subs
Subs.CASNumber = "4-5-13"
Subs.Name = "Some substance"
Subs.DefaultUnit = "kg"
Subs.Update
SP.CreateProcess ptMaterial, PC
Set PL = PC.AddLine(ppProduct, -1)
PL.ObjectName = "Steel 2"
PL.UnitName = "kg"
PL.Amount = "2"
PL.Comment.Add ("My new created process")
PL.CategoryPath = "Chemicals\inorganic"
PC.Update
' create second material process Case
SP.CreateProcess ptMaterial, PC2
Set PL = PC2.AddLine(ppProducts, 0)
PL.ObjectName = "Case 2"
PL.UnitName = "kg"
PL.Amount = "10"
Set Param = PC2.AddParamLine(ptInputParameter, -1)
Param.Name = "A"
Param.Value = "2,3"
' add input from Steel
Set PL = PC2.AddLine(ppMaterialsFuels, -1)
' input from steel
PL.SetProduct "Introduction to SimaPro 7", ptMaterial, "Steel 2"
PL.Amount = "8"
PL.UnitName = "kg"
Set PL = PC2.AddLine(ppAirborneEmissions, -1)
' input from steel
PL.SetSubstance "Some substance", ""
PL.Amount = "A+1"
PL.UnitName = "kg"
PC2.Update
SP.Logout
SP.CloseDatabase
Set SP = Nothing
End Sub

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

凯凯我们等你回来 2024-11-24 14:07:53

鉴于这已经是一年多前的事了。我假设你已经成功了。如果您还没有,我可能知道根本原因可能是什么。

我曾经遇到过同样的错误,从您对服务器、别名和登录名的更改中,我能够使其运行。不同的一件事是您已将项目名称从“Introduction to SimaPro 7”更改为“Project”。老实说,我的 VBA 知识为零(这里不是谦虚)。因此,我推测没有可以打开的项目名称“Project”。我不确定VBA是否会自动创建一个项目,如果它找不到它。您可以尝试创建一个名为“Project”的项目,也可以将其重命名回来。我有兴趣看看这是否有效。

Given that this was more than one year ago. I'm assuming you got this working. If you haven't yet, I might know what the root cause might be.

I used to get the same error and from your changes for server, alias and login, I was able to make it run. One thing that is different is that you have changed the name of the project to "Project" from "Introduction to SimaPro 7". I honestly have zero (not being humble here) VBA knowledge. So, I'm speculating that there is no project names "Project" to open. I'm not sure if VBA would create a project automatically, if it can't find it. You can either try creating a project named "Project" or just rename it back. I am interested to see if that worked.

青衫儰鉨ミ守葔 2024-11-24 14:07:53

自动化错误通常意味着您尝试使用的 COM 库中存在问题。由于它是一个运行时错误,因此可能是非常愚蠢的事情,例如缺少参数或错误的路径或访问权限。在我看来,这也意味着图书馆设计得不是很好。

由于您不是该库的作者,因此您没有太多选择。您可以尝试联系供应商以获取更多文档。你也可以祈祷设计者考虑过日志记录——检查事件日志;如果你幸运的话,你可能会在那里发现一些有趣的东西。

回答你的第一个问题,如果你引用了库并且代码编译了 - 这意味着你已经做了所有事情。

Automation Error usually means that there was a problem within the COM library you try to use. As it is a run-time error, it could be something very stupid, as missing parameter or wrong path or access rights. In my opinion, it also means that the library is not very well designed.

As you are not the author of the library you do not have many options. You can try to contact the vendor to get more documentation. You can also pray that the designer thought about logging - check the event log; if you are lucky you may find something interesting there.

Answering your first question, if you referenced the library and the code compiles - that means that you did everything right there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文