2011-12-07 8 views
0

私はVBAを使用してPDFCreatorを自動化しようとしています。PDFCreatorを使用してVBAからPDFへのHTML

IEで開いたHTMLファイルからPDFの作成を自動化できますか?

ウェブ上で検索した結果、ExcelまたはWordで動作するコードが得られましたが、本当に必要なのは、VBAフォームへのHTMLファイルパスを入力して開き、ブラウザをナビゲートしてPDFに出力することです。

私はVBAでPDFCreatorを制御する方法を知っていますが、IEをPDFCreatorプリンタにどのようにリンクさせるかはわかりません。

答えて

1

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 
関連する問題