Option Explicit

'************************************************************************

Sub Distiller_Convert_Doc2PDF_Dialog_Box()

'************************************************************************

 

'This will convert multiple MS Word documents to PDF files - flaky code!! - see below

'

'Code for Acrobat 5 - Distiller

'Don't try this with Acrobat 7 - locks up Windows

'

'Must change printing preferences for Distiller printer:

'Adobe PDF Settings - un-check the box "do not send fonts to Distiller"

'This can't work unless you DO send the fonts

 

'This will sometimes hang - not sure exactly WHY!

'Happens when Distiller tries to create 2nd document before it has finished the first one

'In Acrobat Distiller print queue, have first document printing, and the other is "stuck"

'

 

'Must Set references

'to Acrodist.exe

'and Acrobat.tlb    Adobe Acrobat XX type Library

'and Microsoft Word object library

 

Dim loWord      As Word.Application

 

'System default printer

Dim lsPrinter   As String

 

Dim MyPathFrom  As String

Dim MyPathTO    As String

Dim MyCount     As String

Dim MyFileName  As String

Dim MyNewName   As String

 

'Create instance of Word

Set loWord = New Word.Application

 

'After this statement, you'll see the Word document instance

loWord.Visible = True

 

MyCount = 0

MyPathFrom = "E:\TV\"

MyPathTO = "E:\TV\PDF\"

 

'Get the default system printer

lsPrinter = loWord.ActivePrinter

 

MyFileName = Dir(MyPathFrom, vbDirectory)

 

Do While MyFileName <> ""

    If MyFileName <> "." And MyFileName <> ".." Then

        If (GetAttr(MyPathFrom & MyFileName) And vbNormal) = vbNormal Then

            If LCase(Right(MyFileName, 3)) = "doc" Or LCase(Right(MyFileName, 3)) = "xls" Then

                MyCount = MyCount + 1

               

                loWord.Documents.Open FileName:=((MyPathFrom) & (MyFileName))

                MyNewName = Left(MyFileName, ((Len(MyFileName) - 4))) & ".pdf"

               

                ' For Acrobat 5

                loWord.ActivePrinter = "Acrobat Distiller"

               

                'Word doesn't seem to use this!

                loWord.Options.DefaultFilePath(wdDocumentsPath) = MyPathTO

               

                'This shows dialog box

                loWord.PrintOut FileName:="", Range:=wdPrintAllDocument, _

                    Item:=wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _

                    Collate:=True, Background:=True, PrintToFile:=False, PrintZoomColumn:=0, _

                    PrintZoomRow:=0, PrintZoomPaperWidth:=0, PrintZoomPaperHeight:=0

                   

                DoEvents

                loWord.ActiveDocument.Close

                DoEvents

            Else

            End If

        Else

        End If

    Else

    End If

 

    MyFileName = Dir

 

Loop

MsgBox MyCount & " have been converted."

 

'Reset system printer

loWord.ActivePrinter = lsPrinter

 

'Now we can close the Word application entirely

loWord.Quit

Set loWord = Nothing

 

End Sub