从Access VBA运行Excel函数

我有一个excel命令button,只是将一张纸的内容复制到另一张。 我试图从访问内运行此命令。 我没有得到一个错误,但是当我从访问运行的代码,信息不复制在Excel中。 代码如下。 有任何想法吗?

Private Sub Command92_Click() Dim x2 As Object Dim GetDBPath As String GetDBPath = CurrentProject.Path & "\" & "Reports.xlsm" Set x2 = CreateObject("Excel.Application") x2.Workbooks.Open (GetDBPath) x2.Visible = True x2.Run CommandButton1_Click x2.ActiveWorkbook.Close (True) x2.Quit Set x2 = Nothing End Sub' 

运行一个例程的名字作为一个string运行。 您还需要在调用中包含工作表的代码名称:

 x2.AutomationSecurity = msoAutomationSecurityLow x2.Run "Sheet1.CommandButton1_Click" 

例如。