使用PDFCreator通过VBA将HTML转换为PDF
我一直在尝试使用VBA自动化PDFCreator 我可以从IE中打开的HTML文件自动创建PDF吗 我在网上的搜索给了我在Excel或Word中工作的代码,但我真正想要的是,我将输入一个VBA表单的HTML文件路径,它应该打开,浏览浏览器并将其打印为PDF使用PDFCreator通过VBA将HTML转换为PDF,html,vba,pdf,Html,Vba,Pdf,我一直在尝试使用VBA自动化PDFCreator 我可以从IE中打开的HTML文件自动创建PDF吗 我在网上的搜索给了我在Excel或Word中工作的代码,但我真正想要的是,我将输入一个VBA表单的HTML文件路径,它应该打开,浏览浏览器并将其打印为PDF 我知道如何通过VBA控制PDFCreator,但我不确定如何将IE链接到PDFCreator打印机。您可以自动将IE打印到任何打印机,包括PDFCreator。 您可能还想检查,它显示了如何让PDFCreator跳过“保存”对话框。我不是Po
我知道如何通过VBA控制PDFCreator,但我不确定如何将IE链接到PDFCreator打印机。您可以自动将IE打印到任何打印机,包括PDFCreator。
您可能还想检查,它显示了如何让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
我们如何设置路径以便将PDF保存在那里?