我正在创建一个Access数据库,其中应该稍后存储不同的客户端,目前它们存储在Excel工作簿中 .

我可以访问SQL数据库的数据(我无法更改任何内容)当前Excel工作表从中获取客户端名称和其他信息,我也希望在我的Access数据库中 . 问题是Excel只有一个接口可以连接到数据库 . 它是带有宏的Excel AddIn,我无法访问其代码 .

我的解决方案是我在Access中运行代码调用Excel工作表中的宏并调用Addin宏 . 但它不起作用......

它完全运行Excel宏,但是当它尝试运行其他Excel宏时,它会失败 . 有时(当我更改Excel宏代码时它会有所不同)我在Access VBA编辑器中收到此错误:

运行时错误'-2147417851(80010105)'对象'_Application'的'Run'方法失败

Note: 我已经将文本从德语翻译成英语,所以它可能不是确切的错误文本 .

有时我从Excel得到一个错误,这意味着无法找到包含AddIn宏的工作表,但安装了插件,当我调试通过宏时它完美地工作 .

安装了AddIn我在for循环中使用 Application.Addins(5).Name 检查了它 .

我已经搜索了2天,我没有进一步,到目前为止我还没有找到有同样问题的人 .

这是我的Access VBA代码:

Public Sub getData(portfolioNumber As String)

Dim xlApp As Object

Dim sFile As String
Dim sClientName As String
Dim sOtherData As String

sFile = CurrentProject.Path & "\ImportSheet.xlsm"
Set xlApp = CreateObject("Excel.Application")
xlApp.Workbooks.Open sFile
xlApp.Cells(5, 6).Value = portfolioNumber
xlApp.Cells(6, 6).Value = portfolioNumber

xlApp.Run "importAMSData"
sClientName = xlApp.Cells(8, 8).Value
sOtherData = xlApp.Cells(8, 9).Value
xlApp.Workbooks.Close

MsgBox (sClientName & " " & sOtherData)

Set xlApp = Nothing

End Sub

这是我的Excel VBA代码,它应该调用另一个宏:

Public Sub importAMSData()

Dim iLastRow As Double
Dim iLastCol As Double
Dim dErrNo As Double

Dim ws As Worksheet
Dim wb As Workbook

Dim aAddin As AddIn

Dim wbOpen As Boolean

Set ws = ThisWorkbook.Sheets(1)

ws.Activate

iLastRow = ws.Cells(ws.Rows.Count, 2).End(xlUp).Row
iLastCol = ws.Cells(7, ws.Columns.Count).End(xlToLeft).Column

If iLastRow > 7 And iLastCol > 1 Then
ws.Range(ws.Cells(8, 1), ws.Cells(iLastRow, iLastCol)).ClearContents
End If

wbOpen = False

ws.Cells(1, 2).Select

默认情况下应该安装AddIn,但是在没有工作之后我尝试重新安装它

Set aAddin = Application.AddIns.Add("C:\Program Files\Microsoft Office\Office14\XLSTART\SPEZM.xlam")

aAddin.Installed = True

Application.Run "SPEZM.xls!import"

我也尝试过:

aAddin.Application.Run "import"

通常(意味着总是如果没有发生其他错误)这里出现一个错误,说Excel没有找到Sheetname.xls但安装了AddIn我已经检查过了 .

感谢你的帮助,对不起这个长期的问题感到抱歉 .