将网页转换为PDF并将其保存在特定的文件夹中

时间:2019-07-11 12:29:26

标签: html vba

我正在尝试将网页转换为PDF,Pdf需要保存在桌面的一个特定文件夹中。我粘贴了下面的代码,可以很好地制作PDF,问题是,PDF正在询问保存位置并弹出对话框。那么如何自动将PDF保存在一个文件夹中。请帮助。

Sub print_PDF()
Dim Explorer As Object
Dim folderPath As String
Dim eQuery As Long
Dim i As Integer
Dim FileAndLocation As Variant
Dim strPathLocation As String
Dim strFilename As String
Dim strPathFile, ChDir As String

strPathLocation = "C:\Desktop\Printed"
strFilename = "makingpdf"
strPathFile = strPathLocation & strFilename

SetDefaultPrinter "CutePDF Writer"

Set Explorer = CreateObject("InternetExplorer.Application")
Explorer.navigate "https://www.google.com/"
Set Explorer = New InternetExplorerMedium
sURL = "https://www.amazon.in/"
With Explorer
.navigate sURL
.Visible = True
End With
TryAgain:
    Application.Wait Now + TimeSerial(0, 0, 6)
    eQuery = Explorer.QueryStatusWB(6)  'get print command status       
    If eQuery And 2 Then
        Explorer.ExecWB 6, 2, "", "" 'print dialogbox is coming..need to be automated for specific folder.......
    Application.Wait Now + TimeSerial(0, 0, 6)
    Else
        GoTo TryAgain
    End If
End Sub
Public Sub SetDefaultPrinter(ByVal printerName As String)
Dim oSH As WshNetwork
Set oSH = New WshNetwork
oSH.SetDefaultPrinter printerName
Set oSH = Nothing
End Sub

0 个答案:

没有答案
相关问题