0

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.

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
  • There is no code showing. You may need to edit your question. –  Jul 11 '19 at 12:37
  • use selenium basic vba and chrome then you can [specify default download folder](https://stackoverflow.com/a/53912638/6241235) – QHarr Jul 11 '19 at 12:43
  • 1
    Qharr: Problem is, i can't use other browser except IE. :( – Soumyakanti De Jul 11 '19 at 12:45
  • Mabe you can do with settings i.e. change the default download path and then https://superuser.com/questions/246553/how-to-disable-file-download-popup-in-internet-explorer Not something I have ever done. – QHarr Jul 11 '19 at 13:02
  • i have to run these code in loop.. so how do i give PDF file name dynamically? Note: Name will be mentioned in excel A column. – Soumyakanti De Jul 11 '19 at 15:31

0 Answers0