Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik GA: Multivariate Time Series in Qlik Predict: Get Details
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Macro in Qlikview

Hi all,

I have a problem with a macro.

I want to execute this macro at the end of the reload.

It's working when i reload my application manually.

But I have a ".bat" for reload my application and with this, it's not working.

My macro send a report by email :

Sub Dagrapport

Set WSHNetwork = CreateObject("WScript.Network")

WSHNetwork.SetDefaultPrinter "QlikViewPDF"

vReport = "RP01" 'Set report

vName = "TITRERAPPORT" 'Name of output pdf

ActiveDocument.PrintReport(vReport), "QlikViewPDF", false 'Printreport

reportFile = "C:\Program Files (x86)\QlikView\PDF\" & vName &".pdf" 'Setting outputname

printReportPDF vReport,reportFile

ActiveDocument.GetApplication.Sleep 5000

zendDagrapport reportFile

End sub

'===========================================================================

FUNCTION printReportPDF(reportID, pdfOutputFile)

    Set WSHShell = CreateObject("WScript.Shell")

     WSHShell.RegWrite "HKCU\Software\QlikViewPDF\OutputFile", pdfOutputFile, "REG_SZ"

     WSHShell.RegWrite "HKCU\Software\QlikViewPDF\BypassSaveAs", "1", "REG_SZ"

    ActiveDocument.PrintDocReport reportID

    set WSHShell = nothing   

END FUNCTION

'===========================================================================

function zendDagrapport(PDFOutputFile)

Dim objEmail

Const cdoSendUsingPort = 2 ' Send the message using SMTP

Const cdoAnonymous = 0 'Do not authenticate

Const cdoBasic = 1 'basic (clear-text) authentication

Const cdoNTLM = 2 'NTLM

SMTPServer = "************************************"

Const SMTPPort = 25 ' Port number for SMTP

Const SMTPTimeout = 60 ' Timeout for SMTP in seconds

'Sending mail

Set objEmail = CreateObject("CDO.Message")

Set objConf = objEmail.Configuration

Set objFlds = objConf.Fields

With objFlds

'---------------------------------------------------------------------

' SMTP server details

.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort

.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SMTPServer

.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoAnonymous

.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = SMTPPort

.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False

.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = SMTPTimeout

.Update

'---------------------------------------------------------------------

End With

objEmail.To = "************************" 'Email Recipient

objEmail.From = "****************************************" 'Email Sender

objEmail.Subject = "Yield Report" ' Subject

objEmail.TextBody = "Please find enclosed the Yield Report for the last week.  " 'Text Body

objEmail.AddAttachment PDFOutputFile ' Attachement

objEmail.Send

Set objFlds = Nothing

Set objConf = Nothing

Set objEmail = Nothing

' msgbox ("Test Mail Sent")

end function

Please help me.

Thanks.

1 Reply
giakoum
Partner - Master II
Partner - Master II