标题:批量打印excel的一段代码,F8能打印出列表中所有excel文件,为何F5只能打印 ...
只看楼主
xingming022
Rank: 1
等 级:新手上路
帖 子:103
专家分:9
注 册:2015-1-26
结帖率:50%
已结贴  问题点数:20 回复次数:3 
批量打印excel的一段代码,F8能打印出列表中所有excel文件,为何F5只能打印一张?

Private Sub Command3_Click()
     Dim RetVal As Long
     Dim ShExInfo As SHELLEXECUTEINFO
     
     Dim I As Integer
     Dim Mypathname As String
     For I = 0 To List1.ListCount - 1
             Mypathname = List1.List(I)

             With ShExInfo
                 .cbSize = Len(ShExInfo)
                 .fMask = &H40
                 .hwnd = 0
                 .lpVerb = "print"
                 .lpFile = Mypathname
                 .lpParameters = ""
                 .lpDirectory = vbNullChar
                 .nShow = 0
             End With
            
             RetVal = ShellExecuteEx(ShExInfo)
            
             If RetVal = 0 Then
                 Exit Sub
             End If
     Next
 End Sub


 Public Type SHELLEXECUTEINFO
      cbSize As Long
      fMask As Long
      hwnd As Long
      lpVerb As String
      lpFile As String
      lpParameters As String
      lpDirectory As String
      nShow As Long
      hInstApp As Long
      lpIDList As Long
      lpClass As String
      hkeyClass As Long
      dwHotKey As Long
      hIcon As Long
      hProcess As Long
  End Type
搜索更多相关主题的帖子: 打印 excel Long String End 
2019-05-16 12:43
wufuzhang
Rank: 9Rank: 9Rank: 9
来 自:广州
等 级:贵宾
威 望:21
帖 子:206
专家分:1346
注 册:2017-8-9
得分:20 
回复 楼主 xingming022
你可以尝试一下,执行RetVal = ShellExecuteEx(ShExInfo)后暂停几秒钟(可以用Sleep(5000)函数),
这样打印机有打印的时间,然后再执行后面的语句。

不经历千百遍的调试,怎能体会成功时那一刹那的喜悦。
2019-05-16 22:31
xingming022
Rank: 1
等 级:新手上路
帖 子:103
专家分:9
注 册:2015-1-26
得分:0 
回复 2楼 wufuzhang
非常感谢,已经搞定了,再请教下,为何打印excel,需要sleep,打印word或者txt就不用?
2019-05-20 17:59
wufuzhang
Rank: 9Rank: 9Rank: 9
来 自:广州
等 级:贵宾
威 望:21
帖 子:206
专家分:1346
注 册:2017-8-9
得分:0 
回复 3楼 xingming022
我猜可能是Excel是网格,在打印时,需要给打印机传送的数据比较多;
而Word和txt格式数据比较少,很短的时间就传送完了,
其实,当Word、txt要打印的内容非常多时,可能也要用Sleep来等待。

不经历千百遍的调试,怎能体会成功时那一刹那的喜悦。
2019-05-20 18:09



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-494755-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.099297 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved