Option Explicit Private Sub Command1_Click()

Dim objExcel As Object
Dim objWorkbook As Object

' 创建 Excel.Application 对象并打开指定文件
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open('E:\检测设备\vba测试\测试\导热系数测定仪_数据导入模板.xlsm')

' 运行 Excel 工作簿中名为 'CommandButton3_Click' 的按钮函数
objExcel.Run '导热系数测定仪_数据导入模板.xlsm'!CommandButton3_Click'

' 关闭工作簿和 Excel 应用程序
objWorkbook.Close False ' 不保存修改
objExcel.Quit

' 释放对象资源
Set objWorkbook = Nothing
Set objExcel = Nothing

End Sub

VBA 代码示例:使用 Excel 应用程序打开并运行另一个工作簿的按钮函数

原文地址: https://www.cveoy.top/t/topic/ouFZ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录