Results 1 to 8 of 8
  1. #1
    Lounger
    Join Date
    Mar 2001
    Location
    NSW, Australia
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Print doc to PDF (2003)

    Courtesy of Hans:

    Try using ShellExecute:

    Put the following declarations at the beginning of a module:

    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
    (ByVal hwnd As Long, _
    ByVal lpOperation As String, _
    ByVal lpFile As String, _
    ByVal lpParameters As String, _
    ByVal lpDirectory As String, _
    ByVal nShowCmd As Long) As Long

    Private Const SW_SHOWNORMAL = 1

    Public Sub PrintPDF(fn As String)
    Dim lngResult As Long
    lngResult = ShellExecute(0&, "Print", fn, 0&, 0&, SW_SHOWNORMAL)
    If lngResult <= 32 Then
    MsgBox "Something went wrong.", vbExclamation
    End If
    End Sub

    To print test.pdf, use

    Call PrintPDF("test.pdf")

    or

    Dim fn As String
    fn = "test.pdf"
    Call PrintPDF(fn)

  2. #2
    Lounger
    Join Date
    Mar 2001
    Location
    NSW, Australia
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Print doc to PDF (2003)

    OOoops - jumped the gun with my reply - however, I'm sure someone will help out. Sorry I had my upside-down glasses on.

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Print doc to PDF (2003)

    Try recording a macro in Word of printing a document to PDF. This should give you the exact name of the PDF printer.
    You can then probably use something like

    Dim strOriginalPrinter As String
    strOriginalPrinter = gappWord.ActivePrinter
    gappWord.ActivePrinter = "Name of the PDF printer"
    gappWord.ActiveDocument.PrintOut
    gappWord.ActivePrinter = strOriginalPrinter

  4. #4
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Print doc to PDF (2003)

    Of course Hans' code works just fine. But there's a little gotcha: it sets the system default printer to the chosen printer. So there's a - admittedly slim - chance that another (background) application's printout is also redirected to that printer. This can be avoided by inserting, right after the line strOriginalPrinter = gappWord.ActivePrinter:

    <font face="Georgia">With Dialogs(wdDialogFilePrintSetup)
    .DoNotSetAsSysDefault = True
    .Execute
    End With</font face=georgia>

    Alternatively, this Dialog panel can be used to pick the desired (PDF) printer from the list of installed printers to make things more generic. This also eliminates the need to know the exact name of the printer to put it in the code. Simply use .Show instead of .Execute in the code above. In the panel, doubleclick the name of the printer and then click the Close button. So the whole Sub would look like:

    <font face="Georgia"> Sub PrintToOtherPrinter(strDocName As String)
    Dim strOriginalPrinter As String
    strOriginalPrinter = gappWord.ActivePrinter
    With Dialogs(wdDialogFilePrintSetup)
    .DoNotSetAsSysDefault = True
    .Show
    End With
    gappWord.ActiveDocument.PrintOut
    gappWord.ActivePrinter = strOriginalPrinter
    End Sub
    </font face=georgia>

  5. #5
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Print doc to PDF (2003)

    If you have installed the Adobe PDFMaker macro then you can try
    <code>Application.Run MacroName:="AdobePDFMakerA.AutoExec.ConvertToPDF"</code>

    StuartR

  6. #6
    Star Lounger
    Join Date
    May 2006
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Print doc to PDF (2003)

    Thanks much to HansV, JanB, StuartR, and lorraine.

    You have provided me with some good options to work with. And none looked like what I had been trying to work out, look nothing like I expected.

    I probably won't get to test this out until the weekend (so there is still time for more suggestions), but I will return with my final decision as example for others.

    When I return I hope it will be with the final solution, not more questions.

    Thank you again.....

  7. #7
    Star Lounger
    Join Date
    May 2006
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Print doc to PDF (2003)

    In Access I have written VBA to create a Word document based on a template. I use code to write to the Word document, and Save it.
    Now I would like to print the Saved document to a PDF file. Systems have Adobe Acrobat, version 7.
    Is there a way that I can use VBA to have Acrobat open the Word.doc and print to the Acrobat distiller?

    Here is the last line of the VBA for Word:

    'Save the document with the save name just created
    gappWord.ActiveDocument.SaveAs strSaveNamePath

    I thought I could add"
    gappWord.ActiveDocument.PrintOut( ?????)
    I need help with the syntax for PrintOut to include all pages to the PDF distiller which is not the default printer

  8. #8
    Star Lounger
    Join Date
    May 2006
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Print doc to PDF (2003)

    I have had a chance to look at PDFMaker macro suggestion. It apears that full Acrobat is needed vs. Reader. So this may be a cost prohibitive choice if stations do not have full Acrobat already..

    I have just tried another alternative approach that uses no additional programming, but does require an inexpensive utility..

    PDF995 allows me to create a PDF printer, it can also be shared on the server. ("995" is for the $10 pricetag). They have a link to OmniFormat.
    OmniFormat has a utility used with PDF995 that allows me to define folders, and document source types to be converted to PDF. The folder is monitored, as soon as a anyname.doc shows up in the folder, it is immediately converted into anyname.PDF and the anyname.doc file is deleted. You can also start to monitor an existing folder and all existing documents of the defined type(s) will be instantly converted, no need to do anything else.

    I have used PDF995 for a number of years, but never tried OmniFormat before this. The PDF printer available for all programs is a nice tool to have.

    Initial testing looks pretty good, but there will probably be some "gotcha"s. Downside is the need to install other software in addition to the database.
    By using VBA that will be eliminated.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •