• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Convert Webpage to pdf and save it in specific folder

soumyade5

New Member
I am trying to convert webpage to PDF and that Pdf need to be saved in one specific folder in desktop. I have pasted the below code which is working fine to make PDF, problem is ,,PDF is asking save location and popping up dialog box. So how to save PDF automatically in one folder.. please help.

Code:
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)      
    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
 
Last edited by a moderator:
As far as I know, there isn't a reliable method.

One thing you can try is use .Sendkeys to simulate clicking a button etc. But this is unreliable at best.

Only reliable method that I now of without any manual intervention, requires VBA to interact with 3rd-party PDF software such as PDF Creator to convert HTML to PDF.
 
Back
Top