VBA Print by PDFCreator

0

I'm trying to print an IE file through PDFCreator, in my searches I could not find a way in VBA to perform this process, until I found an algorithm that says to do this, but I could not solve a problem with WshNetwork, it gives me as Compile Error, as non-user-defined type. I would like to know if anyone knows a way to work with PDFCreator by vba, make it print a page, using the program, completely, that is, where I can determine the file name and put the path, if it is not possible, something that gives me a point or something.

    
asked by anonymous 03.01.2018 / 13:57

1 answer

1

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

Follow the form to which 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
    
20.02.2018 / 21:33