[英]Run Excel Function From Access VBA
I have an excel command button which simply copies the contents of one sheet to another.我有一个 excel 命令按钮,它只是将一张纸的内容复制到另一张纸上。 I am trying to run this command from within access.
我正在尝试从访问中运行此命令。 I do not get an error, however when I run the code from access, the information is not copied in excel.
我没有收到错误消息,但是当我从 access 运行代码时,信息不会复制到 excel 中。 The code is below.
代码如下。 Any ideas?
有任何想法吗?
' '
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'
Run takes the name of a routine to run, as a String. Run 将要运行的例程的名称作为字符串。 You will also need to include the code name of the worksheet in the call:
您还需要在调用中包含工作表的代码名称:
x2.AutomationSecurity = msoAutomationSecurityLow
x2.Run "Sheet1.CommandButton1_Click"
for example.例如。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.