Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
marco_puccetti
Partner - Creator
Partner - Creator

Report macro Debug

Hello, i need to create a macro in order to print the Application's reports, but i can't find the debug option.

Is it possible to debug vb macro in a sort of manner the script editor?

Thanks

Marco

9 Replies
robert_mika
Master III
Master III

There is no debug as such but some of the errors are being indicated  on the right hand side of the Check button(Currently is ***Changed****:)

27-Apr-15 1-37-05 PM.jpg

robert_mika
Master III
Master III

If you need an adivce ,post your code

robert_mika
Master III
Master III

marco_puccetti
Partner - Creator
Partner - Creator
Author

Thanks, i take the occasion to ask if have you got any sample of print module vb, in order to print with pdf creator.

I have this code that doesn't work properly.

It create a deadlock and doesn't print the espected files.

Below the code:

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

' Function RICHIAMATE

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

function printReportPDF(NomeReport)

    'attiva la stampante PDFCreator

  ActiveDocument.PrintReport NomeReport, "PDFCreator", FALSE

end function

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

Sub StampaPDF

    Dim i

    Dim FieldValue, oszFieldName, oszFile, oszFileName

    StampaPDF = False

    oszFieldName = "ABI"

    oszFile      = "C:\Users\m.puccetti\Desktop\QLIK_REPORT\"

    oszFileName  = "Report_"

    MsgBox("STAMPAPDF")

    'Un pdf per ogni ABI

    set mySelections = ActiveDocument.Fields(oszFieldName).GetPossibleValues

    For i = 0 to mySelections.Count - 1

        FieldValue = mySelections.Item(i).text

        ActiveDocument.Fields(oszFieldName).Select FieldValue

        oszFileName = oszFileName & FieldValue

        call CreaPDF(oszFile & oszFileName & ".pdf", "RP04")

    Next

end Sub

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

function CreaPDF(sDestination,sReport)

  set oFS = CreateObject("Scripting.FileSystemObject")

  currentStatus = fileExists (sDestination)

  if(currentStatus) then

  oFS.DeleteFile sFile

  end if

  'Selezioni da attivare

  ActiveDocument.Fields("TRAMITE_CONTABILE").Select "05000"

  ActiveDocument.Fields("TIPO_COLLEGAMENTO").Select "0"

    ActiveDocument.GetApplication.WaitForIdle

  call printReportPDF(sReport)

  checkoutput(sDestionation)

  currentStatus = fileExists (sDestination)

  if(currentStatus) then

  MSGBOX("CREATO DOC: " & sDestionation)

  end if

  ActiveDocument.ClearAll

  set oFS=nothing

  CreaPDF = True

end function

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

Function CheckPresenza(ReportArr,NomeRep)

  Dim Presente

  Presente = False

  For i=0 to ReportArr.Count-1

  If ReportArr.Item(I).Text=NomeRep then

  Presente=True

  End If

  Next

  CheckPresenza=Presente

End Function

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

function DeleteFile(pdfFile)

  'Se esiste già un report con lo stesso nome di quello da stampare lo cancelliamo

  Set fileTest = CreateObject("Scripting.FileSystemObject")

  if fileTest.FileExists(pdfFile) then

  fileTest.DeleteFile (pdfFile)

  end if

  set fileTest = nothing

end function

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

function checkoutput(pdfFile)

  'Attendiamo fino alla generazione del REPORT

  Set fileTest = CreateObject("Scripting.FileSystemObject")

  currentStatus=false

  while (not currentStatus)

  currentStatus = fileTest.FileExists (pdfFile)

  ActiveDocument.GetApplication.Sleep 1000

  wend

  set fileTest = nothing

end function

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

function fileExists (sFile)

  currentStatus=false

  set oFS = CreateObject("Scripting.FileSystemObject")

  fileExists = oFS.FileExists (sFile)

  set oFS=nothing

end function

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

Thanks

Not applicable

Hi Marco,

you should modify printer configuration in order to avoid request of path and name of destination file.

Something like this:

     Set WSHShell = CreateObject("WScript.Shell")

    WSHShell.RegWrite "HKCU\Software\PDFCreator\Program\AutosaveDirectory",  pdf_path, "REG_SZ"

    WSHShell.RegWrite "HKCU\Software\PDFCreator\Program\AutosaveFilename", pdf_name , "REG_SZ"

    WSHShell.RegWrite "HKCU\Software\PDFCreator\Program\UseAutosave", "1", "REG_SZ"

    WSHShell.RegWrite "HKCU\Software\PDFCreator\Program\UseAutosaveDirectory", "1", "REG_SZ"

Alex

marco_puccetti
Partner - Creator
Partner - Creator
Author

This code has to be used at which point of the above code?

This allow also the generation of multiple pdf that now is not done?

Marco

marco_puccetti
Partner - Creator
Partner - Creator
Author

I have tried and the name of the file is generated properly, but it still continue to pause the execution after the first invocation of this routine:  ActiveDocument.PrintReport NomeReport, "PDFCreator", FALSE

Is it correct?

Thanks

Marco

Not applicable

The code should be inserted before the call of function ActiveDocument.PrintReport .

About application hang after print of first pdf, check if name of generated pdf contains two times extension .pdf.

In this case you can modify row

    WSHShell.RegWrite "HKCU\Software\PDFCreator\Program\AutosaveFilename", pdf_name , "REG_SZ"

inserting pdf_name without extension.

Alex

marco_puccetti
Partner - Creator
Partner - Creator
Author

Ok!

Thanks