Skip to main content
Announcements
Get Ready. A New Qlik Learning Experience is Coming February 17! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
camilo
Contributor III
Contributor III

My weekly PDF report mutated into an anual one after January first this year

Hi, Thanks to the usefull information in this forum I managed to create a PDF report that it´s automatically send weekly on QV 8.5 to the users emails.

But after January first this year it began to show all the information stored on the qvd which is several months instead of just a weekly one.

This is the macro I´m using, sorry but I couldn´t managed to give it a good format:



sub CreaPDF
dim Meses(12)
Meses(01) = "Ene"
Meses(02) = "Feb"
Meses(03) = "Mar"
Meses(04) = "Abr"
Meses(05) = "May"
Meses(06) = "Jun"
Meses(07) = "Jul"
Meses(08) = "Ago"
Meses(09) = "Sep"
Meses(10) = "Oct"
Meses(11) = "Nov"
Meses(12) = "Dic"

ff = ActiveDocument.GetProperties.LastReloadTime
Activedocument.ClearAll(False)
ActiveDocument.Fields("Año").Select(cStr(year (ff - 1)))
ActiveDocument.Fields("Mes").Select(Meses(Month(ff - 1)))
ActiveDocument.Fields("Día").Select(cStr(day (ff - 1)))


if weekday(ff - 1) = 1 then
ActiveDocument.Fields("Año").clear
ActiveDocument.Fields("Mes").clear
ActiveDocument.Fields("Día").clear
ActiveDocument.Fields("Semana").Select(datepart("ww",(ff-2)))
set Dia = ActiveDocument.Fields("Día").GetPossibleValues
msgcam = ""

for k=0 to Dia.Count-1

ActiveDocument.Fields("Día").Select(Dia.item(k).Text)
set cam = ActiveDocument.Fields("Cámara").GetPossibleValues
antcam = 0
for i=0 to cam.Count - 1

if (cam.item(i).number - antcam) > 1 then
msgbox(cam.item(i).number)
for u = antcam + 1 to cam.item(i).number - 1
msgcam = msgcam & "Día " & Dia.item(k).Text & "," & " Cámara " & u & "," & " 24 Horas sin Mediciones " & chr(10)
next
end if

ActiveDocument.Fields("Cámara").Select(Cam.item(i).text)
set med = ActiveDocument.Fields("Veces").GetPossibleValues
for j=0 to med.Count-1

if med.Item(j).Number <= 50 then
msgcam = msgcam & "Día " & Dia.item(k).Text & "," & " Cámara " & Cam.item(i).text & ", " & round(((72 - med.item(j).number) / 3)) & " Horas sin Mediciones " & chr(10)
end if

next
ActiveDocument.Fields("Cámara").Clear
antcam = cam.item(i).number

next

next
if msgcam <> "" then
'msgbox(msgcam)
set v = ActiveDocument.Variables("msgcam")
v.SetContent msgcam, true
end if

ActiveDocument.Fields("Año").clear
ActiveDocument.Fields("Mes").clear
ActiveDocument.Fields("Día").clear
ActiveDocument.Fields("Semana").Select(datepart("ww",(ff-2)))

ReporteCamaras = "C:\QV\Piloto\Reportes\Camaras\ve\TempCamaras.pdf"

printReportPDF "RP02", ReporteCamaras

ActiveDocument.GetApplication.Sleep 300000

Set objMail = CreateObject("CDO.Message")
objMail.From = "mail"
objMail.To = "mail"
objMail.Cc = "mail"
objMail.Subject = "Subject"
objMail.TextBody = "text"
on error resume next

objMail.AddAttachment "c:\QV\Piloto\Reportes\Camaras\ve\TempCamaras.pdf"
objMail.send
Set objMail = Nothing

end if

end sub

function printReportPDF(oReport, 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.PrintReport oReport, "QlikViewPDF", false
set WSHShell = nothing
end function



Thanks, any help is more than welcome

Camilo

0 Replies