Hi Jay,
Thanks for your input.
It helped me solve my problem.
I've modified my code as below
Private Sub PrintButton_Click()
Dim oDoc As Document
Dim FrmFld As FormField
Dim Rg As Range
Dim HLink As Hyperlink
Dim docName As String
Dim docExtension As String
Dim blank As String
Shell "wscript " & Chr(34) & "C:\pauseQueue.vbs" & Chr(34)
Application.ScreenUpdating = False
Set oDoc = ActiveDocument
ActiveDocument.PrintOut
For Each FrmFld In oDoc.FormFields
If FrmFld.Type = wdFieldFormCheckBox Then
If FrmFld.CheckBox.Value = True Then
Set Rg = FrmFld.Range.Cells(1).Range
Set HLink = Rg.Hyperlinks(1)
docName = HLink.Address
docExtension = Mid(docName, InStrRev(docName, ".") + 1)
Select Case docExtension
Case "doc"
Application.PrintOut , , , , , , , , , , , , Chr(34)
& docName & Chr(34)
Case "txt"
Application.PrintOut , , , , , , , , , , , , Chr(34)
& docName & Chr(34)
Case "dot"
Application.PrintOut , , , , , , , , , , , , Chr(34)
& docName & Chr(34)
Case "rtf"
Application.PrintOut , , , , , , , , , , , , Chr(34)
& docName & Chr(34)
Case "htm"
Application.PrintOut , , , , , , , , , , , , Chr(34)
& docName & Chr(34)
Case "html"
Application.PrintOut , , , , , , , , , , , , Chr(34)
& docName & Chr(34)
Case "pdf"
''Shell "C:\Program Files\Adobe\Reader
9.0\Reader\AcroRd32.exe /t " & chr(34) & docName & chr(34)
Shell "C:\Program Files\Adobe\Acrobat
9.0\Acrobat\Acrobat.exe /n /t " & Chr(34) & docName & Chr(34)
Case "xls"
PrintWorkbook (docName)
Case "ppt"
Shell "C:\Program Files\Microsoft
Office\OFFICE11\POWERPNT.EXE /P " & Chr(34) & docName & Chr(34)
End Select
End If
End If
Next
Application.ScreenUpdating = True
Shell "wscript " & Chr(34) & "C:\resumeQueue.vbs" & Chr(34)
End Sub
Sub PrintWorkbook(ByVal docName As String)
Dim oXL As Excel.Application
Dim oWB As Excel.Workbook
Dim oSheet As Excel.Worksheet
Dim oRng As Excel.Range
Dim ExcelWasNotRunning As Boolean
Dim WorkbookToWorkOn As String
'If Excel is running, get a handle on it; otherwise start a new instance
of Excel
On Error Resume Next
Set oXL = GetObject(, "Excel.Application")
If Err Then
ExcelWasNotRunning = True
Set oXL = New Excel.Application
End If
On Error GoTo Err_Handler
'If you want Excel to be visible, you could add the line: oXL.Visible =
True here; but your code will run faster if you don't make it visible
'Open the workbook
Set oWB = oXL.Workbooks.Open(FileName:=docName)
'Process each of the spreadsheets in the workbook
For Each oSheet In oXL.ActiveWorkbook.Worksheets
'put guts of your code here
oXL.ActiveWorkbook.PrintOut
'get next sheet
Next oSheet
'close the WorkBook
oWB.Close savechanges:=False
If ExcelWasNotRunning Then
oXL.Quit
End If
'Make sure you release object references.
Set oRng = Nothing
Set oSheet = Nothing
Set oWB = Nothing
Set oXL = Nothing
'quit
Exit Sub
Err_Handler:
MsgBox docName & " caused a problem. " & Err.Description, vbCritical, _
"Error: " & Err.Number
If ExcelWasNotRunning Then
oXL.Quit
End If
End Sub
This code works fine, but I had to implement 2 VBScripts, to help me print
out the documents in the correct order. Due to the processing time of the
different document types, the print order in the queue got all messed up.
I've found out that pausing the print queue, and enabling it at the end of
the routine, solves the problem.
The code of the VBScripts below
strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\"
& strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery("Select * from
Win32_Printer")
For Each objPrinter In colInstalledPrinters
ObjPrinter.Resume()
Next
AND the Second File:
strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\"
& strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery("Select * from
Win32_Printer")
For Each objPrinter In colInstalledPrinters
ObjPrinter.Pause()
Next