问题描述
我目前有一个用于批量打印的宏。它运作完美;但是,可以通过使用以下代码设置默认打印机来对打印选项进行硬编码。
CreateObject("WScript.Network").SetDefaultPrinter "\\vs-dc.CCC.internal\RICOH MPC3503 - Office 2nd Flr WKRM"
有人知道打开网络上所有打印机选项的对话框的方法,以便有人可以使用吗?不必将默认设置恢复为原始设置,但是如果这样做,那将是绝对的加分。
我的想法是要以某种方式将表格设置为您选择的打印机 Selected printer = ChosenPrinter
,然后使用它。
CreateObject("WScript.Network").SetDefaultPrinter ChosenPrinter
我还看到了如何使用以下命令将其设置回原始默认值:
ActivePrinter = OrigPrinter
,完成后将其重新设置为该值。
如果有人知道如何将所有这些相互结合在一起,那将是惊人的。如有必要,我将在下面提供完整的代码。
Sub GetFiles(StartFolder As String,Pattern As String,_
DoSubfolders As Boolean,ByRef colFiles As Collection)
Dim f As String,sf As String,subF As New Collection,s
If Right(StartFolder,1) <> "\" Then StartFolder = StartFolder & "\"
f = Dir(StartFolder & Pattern)
Do While Len(f) > 0
colFiles.Add StartFolder & f
f = Dir()
Loop
sf = Dir(StartFolder,vbDirectory)
Do While Len(sf) > 0
If sf <> "." And sf <> ".." Then
If (GetAttr(StartFolder & sf) And vbDirectory) <> 0 Then
subF.Add StartFolder & sf
End If
End If
sf = Dir()
Loop
For Each s In subF
GetFiles CStr(s),Pattern,True,colFiles
Next s
End Sub
。
Sub BatchPrint()
Dim colFiles As New Collection
Dim CustRow,LastRow As Long
Set colFiles = New Collection
CreateObject("WScript.Network").SetDefaultPrinter "\\vs-dc.CCC.internal\RICOH MPC3503 - Office 2nd Flr WKRM"
LastRow = Sheet1.Range("B9999").End(xlUp).Row
Dim countFiles As Integer 'Storing the number of files found
With Sheet1
For CustRow = 3 To LastRow
countFiles = colFiles.Count
GetFiles "C:\Users\Desktop\Test\",Sheet1.Range("B" & CustRow) & ".pdf",colFiles
If countFiles = colFiles.Count Then
Sheet1.Range("B" & CustRow).Interior.ColorIndex = 3
End If
Next CustRow
End With
Dim i As Long
For i = 1 To colFiles.Count
Debug.Print colFiles(i)
PrintFile (colFiles(i))
Next i
Set colFiles = Nothing
End Sub
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)