2011-12-07 3 views
0

나는 VBA를 사용하여 PDFCreator를 자동화하려고 노력해 왔습니다.PDFCreator를 사용하여 VBA를 통해 PDF로 HTML

IE에서 열린 HTML 파일에서 PDF 생성을 자동화 할 수 있습니까?

웹에서의 검색은 Excel 또는 Word 내에서 작동하는 코드를 제공하지만 실제로 원하는 것은 VBA 양식에 HTML 파일 경로를 입력해야하며 브라우저를 탐색하여 PDF로 인쇄해야한다는 것입니다.

나는 VBA로 PDFCreator를 제어하는 ​​방법을 알고 있지만 PDFCreator 프린터에 IE를 어떻게 연결해야하는지 모르겠습니다.

답변

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 
관련 문제