注册 登录
编程论坛 VB.NET论坛

vb.net 指定打印机打印

cokoed4 发布于 2015-10-16 23:08, 2245 次点击
Dim exlApp As New Excel.Application, xlBook As Excel.Workbook, xlSheet As Excel.Worksheet
   xlBook = exlApp.Workbooks.Open(strPath)  
        exlApp.Application.ScreenUpdating = False
        exlApp.Application.DisplayAlerts = False

 For Each xlSheet In xlBook.Sheets
            If xlSheet.Name = "XA" Then
                 WITH  xlSheet
                        .Range("l3").Value=1
                   End With
            End If
 Next

exlApp.ActiveSheet.printout()   '----这里打印出来为用系统默认打印机的  如何让他能弹出打印机选择框并选择指定打印机
 xlBook.Close(False)
        exlApp.Application.ScreenUpdating = True
        exlApp.Application.DisplayAlerts = True
        exlApp.Quit()
 


我尝试在代码运行时候用了PrintDialog 弹出打印机对框框并选择 但根本没作用,还是用默认的打印,请问有什么办法可以实现指定打印机打印
1 回复
#2
cokoed42015-10-17 10:48
还是自己解决了,
先捕获打印机名称
  Dim PD1 As New PrintDialog
        PD1.ShowDialog()
        Dim gg As String = Trim(PD1.PrinterSettings.PrinterName)


最后把exlApp.ActiveSheet.printout() 改成xlSheet.PrintOut(ActivePrinter:=gg) 就好了
1