access 中的VBA实现打开一个excel并调用excel中的宏,代码怎么实现的
1个回答
展开全部
你试试如下代码:
ACCESS中:
Sub xx()
Dim xlApp as Object, wb As Object
On Error Resume NExt
Set xlApp = GetObject(,"Excel.Application")
If Not xlApp Is Nothing Then
Set Wb = xlApp.WorkBooks("a.xls")
If Err.Number = 9 Then Set Wb = xlApp.WorkBooks.Open("D:\a.xls")
Else
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set Wb = xlApp.WorkBooks.Open("D:\a.xls")
End if
End Sub
a.Xls工作簿中:
Private Sub WOrkbook_OPen()
Call Sheet1.pp
End Sub
Sheet1工作表中 :
Public Sub pp()
Msgbox "Hello!!"
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询