BTW, let's post the code as it should be:

VB Code:
  1. Private objWord As Word.Application
  2. Private objDocument As Word.Document
  3.  
  4. Private Sub WritePDF(FileName As String)
  5.     Dim fName As String
  6.     Dim pName As String
  7.     Dim p As Printer
  8.     Dim Branch As String
  9.     Dim Path As String
  10.    
  11.     Branch = "Software\Microsoft\Windows NT\CurrentVersion\Print\Printers\Acrobat Distiller"
  12.     Path = GetSettingString(HKEY_LOCAL_MACHINE, Branch, "Port", "")
  13.    
  14.     If Path = "" Then
  15.         Path = "C:\Program Files\Adobe\Acrobat 4.0\PDF Output\"
  16.     Else
  17.         Path = Left$(Path, InStrRev(Path, "\"))
  18.     End If
  19.    
  20.     On Error Resume Next
  21.     Set objWord = GetObject(, "Word.Application")
  22.        
  23.     ' if error then Word wasn't open
  24.     If Err.Number <> 0 Then
  25.         ' open Word
  26.         Set objWord = CreateObject("Word.Application")
  27.     End If
  28.     Err.Clear
  29.    
  30.     On Error GoTo 0
  31.    
  32.     Set objDocument = objWord.Documents.Open(FileName)
  33.    
  34.     ' activate the document
  35.     objDocument.Activate
  36.    
  37.     'Save the default printer name
  38.     pName = Printer.DeviceName
  39.    
  40.     With objWord
  41.  
  42.         On Error Resume Next
  43.         '  I can not find a way to create the files where I want, and this
  44.         'is the default directory... so I delete all the PDF files, and
  45.         'LOG files first. Make sure this is not a problem.
  46.         Kill Path & "*.log"
  47.         Kill Path & "Microsoft Word - *.pdf"
  48.         On Error GoTo 0
  49.  
  50.         'Set the Acrobat Distiller as the default printer
  51.         .ActivePrinter = "Acrobat Distiller"
  52.  
  53.         'Print the File
  54.         .PrintOut FileName:="", Range:=wdPrintAllDocument, item:= _
  55.             wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _
  56.             Collate:=True, Background:=True, PrintToFile:=False, PrintZoomColumn:=0, _
  57.             PrintZoomRow:=0, PrintZoomPaperWidth:=0, PrintZoomPaperHeight:=0
  58.  
  59.         'Wait until the LOG file is created... this means the PDF has just
  60.         'been created
  61.         Do
  62.             DoEvents
  63.         Loop Until Len(Dir(Path & "Microsoft Word - *.log", _
  64.           vbArchive))
  65.                    
  66.         'Get the created PDF filename
  67.         fName = Dir(Path & "Microsoft Word - *.pdf", vbArchive)
  68.  
  69.         'Create the PDF Filename out of the DOC filename
  70.         FileName = Trim$(FileName)
  71.         FileName = Left$(FileName, Len(FileName) - 4) & ".pdf"
  72.        
  73.         'Copy the file to the same directory where the DOC was.
  74.         FileCopy Path & fName, _
  75.              FileName
  76.         Do Until Len(Dir(FileName, vbArchive))
  77.             DoEvents
  78.         Loop
  79.         MsgBox "The PDF has been created"
  80.        
  81.         'Set the default printer to the original.
  82.         .ActivePrinter = pName
  83.     End With
  84.    
  85.     'Close Word.
  86.      objWord.Quit
  87.    
  88.     ' clean up after our-selves
  89.     Set objWord = Nothing
  90.     Set objDocument = Nothing
  91.  
  92. End Sub
If we are using a Path variable... let's use it in the whole code.