ExecuteExcel4Macro 打印关闭的工作簿

ExecuteExcel4Macro to print closed workbook

我设法使用 ExecuteExcel4Macro 从工作簿中获取数据。 但是我可以在不打开文件的情况下打印文件中的 sheet 吗?

这是 API 版本:

 Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
                                      (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
                                       ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Const SW_HIDE            As Long = 0&
Sub PrintFile(strFilepath As String)
   ShellExecute Application.hWnd, "Print", strFilepath, 0&, 0&, SW_HIDE
End Sub

然后您的调用代码将使用:

Call PrintFile("C:\path to file.xls")

例如。