Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Using PDFCreator in Word
I wonder if I'm on the right track here? I'm used to writing macros in Excel,
and know nothing about Word (and I do mean NUTH-ING). However, I need to be able to run the following macro in an open Word document to save it as a PDF. The code I've supplied below is what I use in Excel, but I've changed a couple of things like Activesheet to Activedocument. That's about as far as I can get without help. I don't know what to substitute for "UsedRange", and it immediately debugs on pdfjob As PDFCreator.clsPDFCreator Rather than using an Inputbox to put in the path name, I want it to save the document as the "same name as open document.pdf" (that's where myDoc comes in below) Can this code be modified to work, or is it miles away? It kinda looks close to me. Your help is greatly appreciated. Regards, Brett Sub PDF_from_WORD_DOCUMENT() 'EARLY BINDING Dim pdfjob As PDFCreator.clsPDFCreator Dim sPDFName As String Dim sPDFPath As String Dim printer_memory printer_memory = Application.ActivePrinter sPDFName = myDoc 'THIS IS SET FROM A CELL IN EXCEL ' I just want it to be set as the 'current document name.pdf sPDFPath = ActiveDocument.Path & Application.PathSeparator If IsEmpty(ActiveDocument.UsedRange) Then Exit Sub Set pdfjob = New PDFCreator.clsPDFCreator With pdfjob If .cStart("/NoProcessingAtStartup") = False Then MsgBox "Can't initialize PDFCreator.", vbCritical + vbOKOnly, "PrtPDFCreator" Exit Sub End If .cOption("UseAutosave") = 1 .cOption("UseAutosaveDirectory") = 1 .cOption("AutosaveDirectory") = sPDFPath .cOption("AutosaveFilename") = sPDFName .cOption("AutosaveFormat") = 0 .cClearCache End With ActiveDocument.PrintOut Copies:=1, ActivePrinter:="PDFCreator" Do Until pdfjob.cCountOfPrintjobs = 1 DoEvents Loop pdfjob.cPrinterStop = False Do Until pdfjob.cCountOfPrintjobs = 0 DoEvents Loop pdfjob.cClose Set pdfjob = Nothing Application.ActivePrinter = printer_memory End Sub |