Hi Everyone,
Great application and it is a pleasure to work with. A big thank you to all involved.
Now to my question.
I have a small MS Access application that picks up Word documents and prints to PDF and emails them to the required recipients. What I would like to be able to do is hide Word while the application creates the PDF file. Everytime a PDF is created Word opens and is visible to th end user. This can be up to 3 times while each PDF is created.
The code I used was the the one provided in the PDF Creator examples and I changed it slightly to suit my needs. Is there any way of doing the what I require?
Any help would be much appreciated.
Here is the VBA code I use:
ublic Sub PrintToPDF(FileNameForPDF As String, WordDocAndPathToConvertToPDF As String) 'RepName As String)
Dim PDFCreator1 As PDFCreator.clsPDFCreator
Dim DefaultPrinter As String
Dim c As Long
Dim OutputFilename As String
Dim strSaveToDir As String
strSaveToDir = Application.CurrentProject.Path & "\PDF"
If Dir(strSaveToDir, vbDirectory) = "" Then
MkDir strSaveToDir
End If
Set PDFCreator1 = New clsPDFCreator
With PDFCreator1
.cStart "/NoProcessingAtStartup"
.cOption("UseAutosave") = 1
.cOption("UseAutosaveDirectory") = 1
.cOption("AutosaveDirectory") = strSaveToDir
.cOption("AutosaveFilename") = FileNameForPDF
.cOption("AutosaveFormat") = 0 ' 0 = PDF
'.cVisible = False
DefaultPrinter = .cDefaultPrinter
.cDefaultPrinter = "PDFCreator"
.cClearCache
.cPrintFile (WordDocAndPathToConvertToPDF)
.cVisible = False
.cPrinterStop = False
End With
c = 0
Do While (PDFCreator1.cOutputFilename = "") And (c < (maxTime * 1000 / sleepTime))
c = c + 1
Sleep 200
Loop
OutputFilename = PDFCreator1.cOutputFilename
With PDFCreator1
.cVisible = False
.cDefaultPrinter = DefaultPrinter
Sleep 200
.cClose
End With
Sleep 2000 ' Wait until PDFCreator is removed from memory
If OutputFilename = "" Then
MsgBox "Creating pdf file." & vbCrLf & vbCrLf & _
"An error is occured: PDF Creation Time Out!...", vbExclamation + vbSystemModal, "PDF Creation Time Out!..."
End If
End Sub