Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Macro create report and send email not works on accesspoint

Hi, my problem is that I have developed a macro that print and send reports by e-mail. This works perfectly on my Qlikview Desktop but, whe I execute this on accesspoint the code stops in the step ('ActiveDocument.PrintReport reportID, "QlikViewPDF", false'), an I think that my code will stop in next steps when I will solve this as wel. So I think that the best is show you all the code.

Firt of all, I checked in QVMC that the checkboxes allowin execute safe and unsafe macros are checked, and I use IE9 to enter in the accesspoint portal. My code is:

'SUBRUTINA PARA IMPRIMIR INFORMES

set reportFile = nothing

set tempFolder = nothing

set reportID = nothing

set reportName = nothing

sub SendReport()

  

          'tempFolder = "C:\Users\cmartinez\Desktop\QLIKVIEW\ENVIO EMAIL\"

          tempFolder = "C:\"

 

          Set oReports = ActiveDocument.Fields("reportID").GetPossibleValues

          Dim arrReports()

          if oReports.Count > 0 then

 

                    redim arrReports(oReports.Count)

                    for i = 0 to oReports.Count -1

                              reportID = oReports.Item(i).Text

           

                              reportFile = tempFolder & reportID & ".pdf"

 

                              'deleteReport (reportFile) 'Cleaning out any previous report

 

                              'arrReports(i) = reportFile

                              ' Print report to PDF

 

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

                              'printReportPDF reportID, reportFile

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

                              Set WSHShell = CreateObject("WScript.Shell")

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

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

 

                              'QV Print

              ActiveDocument.PrintReport reportID, "QlikViewPDF", false ---> Here the code stops in accesspoint

                              set WSHShell = nothing

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

 

                              ' Check the file is printed, before trying to send it

                              checkOutputFile(reportFile)

                    next

                    ' Send report

                    'sendMail arrReports

 

 

                      'SendMail

 

          else

        

          end if

'           Delete the temporary reports

          'for each item in arrReports

                    'deleteReport(item)

          'next

 

          ' Don't forget to activate Save As again after print!

 

          'call activateSaveAs()

 

          set fileTest = nothing

 

end sub

function deleteReport(rFile)

          set oFile = createObject("Scripting.FileSystemObject")

 

          currentStatus = oFile.FileExists(rFile)

 

          if currentStatus = true then

                    oFile.DeleteFile(rFile)

          end if

          set oFile = Nothing

end function

function activateSaveAs()

          Set WSHShell = CreateObject("WScript.Shell")

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

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

          set WSHShell = nothing

end function

function checkOutputFile(pdfFile)

          Set fileTest = CreateObject("Scripting.FileSystemObject")

          currentStatus = fileTest.FileExists (pdfFile)

 

          if currentStatus = false then

                    rem ** let QV sleep for 1 seconds **

                    ActiveDocument.GetApplication.Sleep 1000

                    checkOutputFile(pdfFile)

          end if

 

          set fileTest = nothing

end function

'

'

''SUBRUTINA PARA ENVIAR EMAIL CON ARCHIVOS ATACHADOS

'Sub SendMail()

'

'' Object creation

Set objMsg = CreateObject("CDO.Message")

Set msgConf = CreateObject("CDO.Configuration")

Dim strMailTo

' Server Configuration

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

msgConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = getVariable("mailServer")

msgConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = getVariable("SMTPport")

msgConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1

msgConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = getVariable("usuarioCorreo")

msgConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = getVariable("password")

msgConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = 1

msgConf.Fields.Update

Set objSelected = ActiveDocument.Fields("ListaDistribucion").GetSelectedValues

Dim ListaMacroEnvio

strMailTo = strMailTo & objSelected.item(0).Text

if(strMailTo = "Lista1") then

      ListaMacroEnvio= getVariable("ListaEnvio1")

end if

if(strMailTo = "Lista2") then

      ListaMacroEnvio= getVariable("ListaEnvio2")

end if

if(strMailTo = "Lista3") then

      ListaMacroEnvio= getVariable("ListaEnvio3")

end if

if(strMailTo = "Lista4") then

      ListaMacroEnvio= getVariable("ListaEnvio4")

end if

if(strMailTo = "Lista5") then

      ListaMacroEnvio= getVariable("ListaEnvio5")

end if

objMsg.To = ListaMacroEnvio

objMsg.From = getVariable("EmailFrom")

objMsg.Subject  = getVariable("Subject")

objMsg.HTMLBody = getText("BodyTX")

objMsg.Sender = getVariable("Sender") 

'ARCHIVOS ADJUNTOS'

' If you have attachment

          Path=tempFolder

          FileName=reportID & "_" & reportName & ".pdf"

         ' MsgBox("ENVIAR?"&Path&FileName)

          objMsg.AddAttachment Path&FileName

Set objMsg.Configuration = msgConf

' Send

objMsg.Send

' Clear

Set objMsg = nothing

Set msgConf = nothing

End Sub

'===================== Function to get the subject etc from variables in document ========

function getVariable(varName)

      set v = ActiveDocument.Variables(varName)

      getVariable = v.GetContent.String

end function

'===================== Function to get the body etc from texobjects in document ========

function getText(obj)

      set mytext = ActiveDocument.GetSheetObject(obj)

      prop = mytext.GetProperties

      getText = prop.Layout.Text.v

end function

My code is very similar to internet sample for printing and sending reports and is necessary tha it works on accesspoint site. The code executes on server and I need that it could be called on th webclient.

If someone has any idea I'd appreciated so much.

Thank you for your responses.

Best Regards

3 Replies
Not applicable
Author

Antes que nada, tienes licencia Publisher?

Si no la tienes no podras ejecutar macros desde clientes a tu servidor. Al menos no la mayoria ni en su total funcionalidad.

http://community.qlik.com/thread/38144

Saludos.

Not applicable
Author

Have you try from the Internet Explorer with the iepluggin? I was having the same problem with the chorme and when I switch to the internet explorer worked perfect

Santiago creo que no es del todo cierta esa afirmacion, lo estoy haciendo desde solo con la licencia server y me funciona

Not applicable
Author

Claro, hay varios casos en los que funciona, hay muchos otros en los que no, en mi caso por ejemplo no pude realizar una recarga del documento desde el lado del cliente usando macros.

Saludos.