VBA Print by Pdfcreator

Asked

Viewed 863 times

0

I am trying to print an IE file by Pdfcreator, in my searches I could not locate a VBA form to perform this process, I even found an algorithm that says to do this, but I could not solve a problem with Wshnetwork, it gives me as Compilation Error, as a type not defined by the user. I wonder if someone knows a way to work with Pdfcreator by vba, make you print a page, using the program, in full, ie where I can determine the name of the file and put the path, if it is not possible, something that gives me a point or something.

  • For automations with programs, windows, buttons. I use the Autoit. In which an Autoit script is created and then can be called by VBA. There are complex ways to work with non-windows software in VBA, one of them is to import libraries. dll, but I find Autoit easier for specific applications

  • 1

    @danieltakeshi I managed to solve this problem the following way, but I appreciate your tip depth and I will guard for future applications. =)

1 answer

1


I was able to find the answer in another forum, which I can’t remember now and unfortunately I can’t give credit to the author.

It follows the way I was able to perform the entire procedure in the background.

'- atribui nome do documento e o caminho para download as devidas variaveis
sPDFNome = "name"
sPDFPath = "c:\teste" & contrato & Application.PathSeparator

'seta a variavel e cria o objeto do pdf creator
Set pdfjob = CreateObject("PDFCreator.clsPDFCreator")

'- verifica se o programa esta aberto - caso esteja ele vai mandar uma mensagem para e finalizar a sub
'- caso nao esteja -
With pdfjob
    If .cStart("/NOProcessingAtStartup") = False Then
        MsgBox "Programa Aberto", vbCritical + vbOKOnly, "prtPDFCreator"
        Exit Sub
    End If

    .cOption("UseAutosave") = 1
    .cOption("UseAutosaveDirectory") = 1
    .cOption("AutosaveDirectory") = sPDFPath
    .cOption("AutosaveFilename") = sPDFNome
    .cOption("AutosaveFormat") = 0 '0 = pdf
    .cClearCache

End With

'- enviar comando para imprimir
'ie.PrintOut copies:=1, ActivePrinter:="PDFCreator"
ie.ExecWB 6, 2, "", ""

'- verifica se o arquivo derminou de ser impresso
Do Until pdfjob.cCountOfPrintjobs = 1
    DoEvents
Loop

pdfjob.cPrinterStop = False

'- verifica se tem algum arquivo na lista de impressao
Do Until pdfjob.cCountOfPrintjobs = 0
    DoEvents
Loop

'- fechar a impressa
pdfjob.cClose

'- larga o objeto
Set pdfjob = Nothing

Browser other questions tagged

You are not signed in. Login or sign up in order to post.