IEを自動化して、PDFCreatorなどの任意のプリンタでドキュメントを印刷できるようにします。
また、this blogをチェックしたい場合は、PDFCreatorに「保存」ダイアログをスキップさせる方法を示します。私はPowerShellの専門家ではないので、これをVBAに変換しようとはしません
'A function that uses IE to print the contents of Google.com to a PDF document
Sub printgoogle()
Dim Explorer As Object
Dim eQuery As Long 'return value type for QueryStatusWB
Dim i As Integer
Dim fTime As Single
'See function below, to set the default printer to PDFCreator. Note: The user would probably be grateful if you checked to see what is the current default printer and set it back when finished printing
SetDefaultPrinter "PDFCreator"
'Connect to Internet Explorer
Set Explorer = CreateObject("InternetExplorer.Application")
'Open some document. This is usually a file on your computer, but I use Google here for test purposes
Explorer.Navigate "www.google.com"
TryAgain:
'Wait for 2 seconds to let IE load the document
fTime = Timer
Do While fTime > Timer - 2
DoEvents
Loop
eQuery = Explorer.QueryStatusWB(6) 'get print command status
If eQuery And 2 Then
Explorer.ExecWB 6, 2, "", "" 'Ok to Print? Then execute the Print (6) command, without displaying the print dialog (2)
'Wait for 2 seconds while IE prints
fTime = Timer
Do While fTime > Timer - 2
DoEvents
Loop
Else
GoTo TryAgain
End If
End Sub
'This function sets the Windows default printer to whatever printer you insert as parameter
Public Sub SetDefaultPrinter(ByVal printerName As String)
Dim oSH As WshNetwork
Set oSH = New WshNetwork
oSH.SetDefaultPrinter printerName
Set oSH = Nothing
End Sub
出典
2011-12-08 17:53:47
GTG