PDA

View Full Version : Export Crystal Report to pdf



msahmed
05-08-2019, 01:18 PM
Hi There,

I am trying to run a report in Internet Explorer and download it in PDF. This is the first time that I'm trying to automate IE and so far I'm able to generate the report, but the report generated is getting opened in Crystal Viewer which I'm not aware of.:dunno

I have been stuck in this code for a while now, any assistance in guiding me with a code to export the report thru VBA will be highly appreciated.

My code is posted below



Sub Trail1()
Dim ie As Object
Dim URL As String
Dim PropertyNames As String
Dim TStatus As String
Dim FrmDate As String
Dim ToDate As String
Dim AsOf As String
Dim Vendor As String
Dim LockBox As String
Dim Parse As String
Dim Destination As String

PropertyNames = ThisWorkbook.Sheets(2).Range("C14").Value
TStatus = ThisWorkbook.Sheets(2).Range("C15").Value
FrmDate = ThisWorkbook.Sheets(2).Range("C16").Value
ToDate = ThisWorkbook.Sheets(2).Range("C17").Value
AsOf = ThisWorkbook.Sheets(2).Range("C18").Value
Vendor = ThisWorkbook.Sheets(2).Range("C19").Value
LockBox = ThisWorkbook.Sheets(2).Range("C20").Value
Parse = ThisWorkbook.Sheets(2).Range("C21").Value
Destination = ThisWorkbook.Sheets(2).Range("C22").Value

Set ie = CreateObject("Internetexplorer.application")
ie.Visible = True

ie.navigate "https://www.yardipcu.com/22466colonysso/pages/SysSqlScript.aspx?Action=FILTER&From=SQLREPORTS&select=reports/rs_jdr_tenant_statement_cobalt.txt"
Do While ie.readyState <> 4 Or ie.Busy: DoEvents: Loop

ie.document.getElementsByClassName("form_button")(0).Click

ie.document.getElementsByName("phMy")(0).Value = PropertyNames
ie.document.getElementsByName("Status")(0).Value = TStatus
ie.document.getElementsByName("begmonth")(0).Value = Format(FrmDate, "MM/YYYY")
ie.document.getElementsByName("endmonth")(0).Value = Format(ToDate, "MM/YYYY")
ie.document.getElementsByName("begdate")(0).Value = Format(AsOf, "MM/DD/YYYY")
ie.document.getElementsByName("vendor")(0).Value = Vendor
ie.document.getElementsByName("lockbox")(0).Value = LockBox
ie.document.getElementsByName("sParse")(0).Value = Parse
ie.document.getElementsByName("RptOutput")(0).Value = Destination

ie.document.getElementsByClassName("filter_submit")(0).Click


'After this the report will be generated in new Crystal Report window
'I am not even able to get the source code from Inspect Element to proceed with the export
'Thanks in advance for the assistance


End Sub



I tried searching code for doing this but still didn't find any. Thanks in advance for the assistance


Best Regards,
Ahmed