回复 3# hnfeng
没打印机,测试不了。。修改如下,可以试试~- Dim objExcel
- Set objExcel = CreateObject("Excel.Application")
- objExcel.Visible = False
- objExcel.DisplayAlerts = False
-
- ' 修改为你的Excel文件路径
- Dim workbookPath
- workbookPath = "C:\路径\至\你的\文件.xlsx"
- Set workbook = objExcel.Workbooks.Open(workbookPath)
-
- ' 指定打印机名称,例如 "\\192.168.1.1\Canon iX6700 series"
- Dim printerName
- printerName = "\\192.168.1.1\Canon iX6700 series"
-
- ' 使用PrintOut方法并指定打印机
- workbook.PrintOut ActivePrinter:=printerName, Collate:=True
-
- workbook.Close SaveChanges:=False
- objExcel.Quit
-
- Set objExcel = Nothing
复制代码 或者这个- Option Explicit
- Dim objExcel, workbook
-
- ' 创建Excel Application对象
- Set objExcel = CreateObject("Excel.Application")
- objExcel.Visible = False
- objExcel.DisplayAlerts = False
-
- ' 打开Excel文件,确保路径是正确的
- Set workbook = objExcel.Workbooks.Open("C:\路径\至\你的\文件.xlsx")
-
- ' 指定打印机
- objExcel.ActivePrinter = "\\192.168.1.1\Canon iX6700 series"
-
- ' 打印工作簿
- workbook.PrintOut
-
- ' 关闭工作簿,不保存更改
- workbook.Close SaveChanges:=False
-
- ' 退出Excel Application
- objExcel.Quit
-
- ' 清理对象
- Set workbook = Nothing
- Set objExcel = Nothing
复制代码
|