将XLL作为自定义操作安装时的OLE自动化错误438 [英] OLE Automation Error 438 when installing an XLL as a custom action
问题描述
我想在使用MSI安装项目时注册XLL.
我正在使用VB.NET安装程序类来做到这一点:
Hi,
I would like to register an XLL while installing a project using MSI.
I am using a VB.NET installer class to do this:
Imports System.ComponentModel
Imports System.Configuration.Install
Imports System.ArgumentException
Imports Microsoft.Office.Interop
Public Class Installer1
Public Overrides Sub Install(ByVal stateSaver As System.Collections.IDictionary)
MyBase.Install(stateSaver)
Dim targetDir = Me.Context.Parameters.Item("targetdir")
targetDir = targetDir.Substring(0, targetDir.Length - 1)
MsgBox(targetDir)
Dim myScript = targetDir + "MySuperAddin.xll"
MsgBox(myScript)
Dim objAddin As Object
Dim objEXL As Excel.Application = DirectCast(CreateObject("Excel.Application"), Excel.Application)
objEXL.Workbooks.Add()
Try
objAddin = objEXL.AddIns.Add(myScript, True)
objAddin(myScript).Installed = True
Catch ex As Exception
MsgBox("cannot open addin. /n Error: " + ex.Message)
Err_Handler:
MsgBox(Err.Description, vbCritical, "Error: " & Err.Number)
End Try
objAddin = Nothing
objEXL.Quit()
objEXL = Nothing
End Sub
End Class
<pre></pre>
当我在桌面上将这些代码作为VB脚本运行时,我没有任何问题.
这是安装插件的非常标准的方法
请查看链接
http://stackoverflow.com/questions/1130301/uninstalling-excel-add -in-using-vbscript
但是,当我在安装过程中运行它时,会得到
错误:438个成员未找到. (来自HRESULTS的异常:0x80020003(DISP_E_MEMBERNOTFOUND))
我尝试使用以下链接找到解决方案:
1) http://support.microsoft.com/kb/172108
和
2) http://support.microsoft.com/kb/213489/
但没有成功.这是OLE自动化对象的明显问题.我真的很感谢一个建议.非常感谢!!
When I run this code as a VB script on my desktop I dont have any issue.
it is a very standard way to install an addin
please see the link
http://stackoverflow.com/questions/1130301/uninstalling-excel-add-in-using-vbscript
However when I run it during the installation I get
Error: 438 Member not found. (Exception from HRESULTS: 0x80020003 (DISP_E_MEMBERNOTFOUND))
I tried to find a solution using the following links:
1) http://support.microsoft.com/kb/172108
and
2) http://support.microsoft.com/kb/213489/
but NO success. it is a clear problem with OLE Automation Object. I would really appreciate a suggestion. MANY THANKS!!
推荐答案
看看我的代码...
我已经创建了Windows应用程序.
我已将表格放在:
1)1个文本框-名称:TxtExcelAddin
2)2个按钮:-a)CmdBrowse(加载项浏览)
b)CmdInstall(安装插件)
Take a look at my code...
I have created windows application.
I have placed on the form:
1) 1x textbox - Name: TxtExcelAddin
2) 2x buttons: - a) CmdBrowse (browse for addin)
b) CmdInstall (install addin)
Public Class Form1
Private Sub CmdBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdBrowse.Click
Dim dlgOF As OpenFileDialog = Nothing
Dim dRes As DialogResult = Windows.Forms.DialogResult.No
Try
dlgOF = New OpenFileDialog()
With dlgOF
.Filter = "Excel 2003 Addin file (*.xla)|*.xla|Excel 2007 Addin file (*.xll)|*.xll"
.FilterIndex = 0
.Multiselect = False
dRes = .ShowDialog()
If dRes = Windows.Forms.DialogResult.OK Then Me.TxtExcelAddin.Text = .FileName
End With
Me.CmdInstall.Enabled = (Me.TxtExcelAddin.Text.Length > 0)
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error no. " & Err.Number)
Finally
dlgOF = Nothing
dRes = Nothing
End Try
End Sub
Private Sub CmdInstall_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdInstall.Click
Dim oExc As Object = Nothing, oAds As Object = Nothing, oAin As Object = Nothing
Dim sFileName As String = String.Empty
Try
'get the name of Addin
sFileName = Me.TxtExcelAddin.Text
'Excel application
oExc = CreateObject("Excel.Application")
'to add addin, we need to create new workbook (to enable Addin manager)
oExc.Workbooks.Add()
'collection of Addins
oAds = oExc.AddIns
'add Addin to the list of Addins
oAin = oAds.Add(sFileName, True)
'install Addin
oAin.Installed = True
MsgBox("Excel Addin installed: " & oAin.Installed, MsgBoxStyle.Information, "Information...")
Catch ex As ArgumentException
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error no. " & Err.Number)
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error no. " & Err.Number)
Finally
oExc.Quit()
oAin = Nothing
oAds = Nothing
oExc = Nothing
End Try
End Sub
End Class
我没有使用Interop和安装程序类.代码正在执行,没有错误.
希望对您有所帮助.
I''m not using Interop and installer class. The code is executing without errors.
I hope it will be helpful for you.
这篇关于将XLL作为自定义操作安装时的OLE自动化错误438的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!