Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
hopkinsc
Partner - Specialist III
Partner - Specialist III

help with macro to email pdf report

Hi all,

i am using the following macro to generate and send a report. the macro works on my machine and on our server, but it won't work on a clients server and i have no idea why.

function SendReport()

Set objFSO = CreateObject("Scripting.FileSystemObject")

  objFSO.DeleteFile("C:\QlikView\Reports\*.pdf"), DeleteReadOnly

  MsgBox("Files Deleted")

Set PDFCreator = CreateObject("PDFCreator.clsPDFCreator")

ReportID = "RP02" 'Set report  

vName = "Daily Report_" & Date &".pdf" 'Name of output pdf

PDFCreator.cStart("/NoProcessingAtStartup")

PDFCreator.cOption("UseAutosave") = 1 ' Enable autosave

PDFCreator.cOption("UseAutosaveDirectory") = 1 ' Use a specific save directory

PDFCreator.cOption("AutosaveDirectory") = "C:\QlikView\Reports\"' Set autosave directory

PDFCreator.cOption("AutosaveFormat") = 0 ' Use PDF file type (.PDF extension)

PDFCreator.cOption("AutosaveFilename") = vName ' set the filename

PDFCreator.cPrinterStop = FALSE

ActiveDocument.PrintDocReport "RP02", "PDFCreator" 'Export to PDF File

    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 = "HIDDEN"      'IP-address of your mailserver"

    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

    ActiveDocument.GetApplication.Sleep 5000

 

objEmail.Configuration.Fields.Item _

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

'Name or IP of Remote SMTP Server

objEmail.Configuration.Fields.Item _

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

'Type of authentication, NONE, Basic (Base64 encoded), NTLM

objEmail.Configuration.Fields.Item _

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

'Your UserID on the SMTP server

objEmail.Configuration.Fields.Item _

("http://schemas.microsoft.com/cdo/configuration/sendusername") = "HIDDEN"

'Your password on the SMTP server

objEmail.Configuration.Fields.Item _

("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "HIDDEN"

'Server port (typically 25)

objEmail.Configuration.Fields.Item _

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

'Use SSL for the connection (False or True)

objEmail.Configuration.Fields.Item _

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

'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)

objEmail.Configuration.Fields.Item _

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

objEmail.Configuration.Fields.Update

'==End remote SMTP server configuration section==

   

    objEmail.To = "HIDDEN; HIDDEN"        'Email Recipient

    objEmail.From = "HIDDEN"                        'Email Sender

    objEmail.Subject = "Report"                        ' Subject

    objEmail.TextBody = "Please find attached today's report"        'Text Body

    'objEmail.AddAttachment   ("C:\QlikView\Reports\" & vName &".pdf")

    Dim objFSO, strFolder, objFile, strFileName

  Set objFSO = CreateObject("Scripting.FileSystemObject")

  strFolder = "C:\QlikView\Reports\"

  strFileName = ""

  For Each objFile In objFSO.GetFolder(strFolder).Files

  If Right(LCase(objFile.Name), 4) = ".pdf" Then strFileName = objFile.Path

  Next

  If strFileName <> "" Then objEmail.AddAttachment strFileName

    objEmail.Send

    MsgBox("Sent")

    Set objFlds = Nothing

    Set objConf = Nothing

    Set objEmail = Nothing

   

    end function

   

it gets as far as the line almost at the bottom ' If strFileName <> "" Then objEmail.AddAttachment strFileName' but stops after that, so it looks like its failing on the objEmail.Send part.

Can anyone help please?

3 Replies
hopkinsc
Partner - Specialist III
Partner - Specialist III
Author

Does anyone have any suggestions on this?

stefano_marson
Partner - Contributor II
Partner - Contributor II

I've the same problem and I don't have solution

marcus_sommer

I think if it worked on one server and not on another then it will be caused by server settings and/or security measures. And there a lot of possibilities what could be wrong - it could be simply that the access rights on the filesystem aren't proper or to many / to large attachments or wrong server-ip/user/pw or the server will be blocked by the group policies or ....

It's not easy to find the reasons. I would try to simplify the whole thing and test the mail-server settings within the qmc (test mail), tests without attachments ... in an exclusion method.

- Marcus