本帖最后由 lwz642246 于 2012-5-19 21:19 编辑
自己需要设定自动打印excel文件,下面代码,在设置好默认打印机时能正常执行,但无打印机时直接崩溃退出,不能执行MsgBox(4096, "提示!!", "测试一下", 8)这句,请问怎么容错处理。
#include <Excel.au3>
Local $oExcel = _ExcelBookNew()
With $oExcel.worksheets(1)
.cells(1, 1) = "测试"
.printout
EndWith
Sleep(500)
_ExcelBookClose($oExcel, 0)
MsgBox(4096, "提示!!", "已打印", 8)
谢谢kevinceh,已解决#include <Excel.au3>
Local $oExcel = _ExcelBookNew()
If $oExcel.ActivePrinter = "" Or StringInStr($oExcel.ActivePrinter, "Microsoft") > 0 Then
MsgBox(4096+262144+64, "打印失败!! 找不到打印机", "没有找到默认打印机,无法打印,请选择设置可用的默认打印机", 5)
Else
With $oExcel.worksheets(1)
.cells(1, 1) = "测试"
.printout
EndWith
endif
Sleep(500)
_ExcelBookClose($oExcel, 0)
|