Saving word document as pdf


I am using the function below from within Excel to merge and save documents as word documents.  I'm now trying to figure out how to save these documents as pdf documents.  I am using Access 2003 with Word 2007 (that's how the environment is configured).  Word 2007 does have the pdf addin installed.  I've bolded the area where I thinkg the code should go
Private Function MwMergeExecute() As Boolean
 On Error GoTo Err_MwMergeExecute
              Dim strSQL          As String
              Dim sCopySuccess    As String
              Dim intPos          As Integer
              Dim strName         As String
              'if we're executing a new, temporary, or modified merge def,
              'then we've already prepared the data
              'otherwise prepare the data
     If gblnMergeDefNew = False _
                  And gblnMergeDefTemp = False _
                  And gblnMergeDefModify = False Then
             If MwGetData(gstrDataSource, gstrDataSourceCriteria) = False Then Exit Function
     End If
              'open the mail merge main document
     Set mobjword = CreateObject("Word.Application")
     Set mobjWordMainDoc = mobjword.Documents.Open(FileName:=gstrMainDocName, _
              'this is here for debugging
          '    mobjWord.Visible = True
              'set the active printer
     If gblnSendToPrinter = True Then
         If MwIsValidPrinter(gstrSendToPrinterName, True) _
                      And (gstrSendToPrinterName <> "(Default Printer)" _
                      And gstrSendToPrinterName <> "(Pitney Bowes)") _
                      Then mobjword.ActivePrinter = gstrSendToPrinterName
     End If
              'set the main doc properties
     With mobjWordMainDoc.MailMerge
                  'TO DO: Must redo how main doc type is set, wizard must decide for the user now
    .MainDocumentType = gbytMainDocType
    .SuppressBlankLines = True
    .OpenDataSource Name:=gstrDataSourceFileName, _
                                      LinkToSource:=True, _
                                      SQLStatement:="SELECT * FROM `tblMailMergeWizard_Data`"
                  'merge to one document per record
         If gblnSendToSeparateDocs = True Then
             If MwMergeToSeperateDocs = True Then MwMergeExecute = True
                      'the log is updated by the above proc so goto exit
             GoTo Exit_MwMergeExecute
         End If
                  'merge to a document
         If gblnSendToDoc = True Then
            .Destination = wdSendToNewDocument
             Set mobjWordSendToDoc = mobjword.ActiveDocument
                      'set the send to doc file name to user supplied name - TimeStamp.doc
             If Right$(gstrSendToDocName, 5) = ".docx" Then _
                          gstrSendToDocName = Left$(gstrSendToDocName, Len(gstrSendToDocName) - 5) _
                          & "-" & MwGetTimeStamp & ".docx"
                      'if user wants to edit then close main doc & show destination doc
             If gblnSendToDocAndEdit = True Then
                          'mobjWordMainDoc.Close wdSaveChanges
                 mobjWordMainDoc.Close SaveChanges:=wdDoNotSaveChanges
                 mobjWordSendToDoc.SaveAs (gstrSendToDocName)
                 mobjword.Visible = True
                 GoTo UpdateTheLog
             End If
                      'print it
             If gblnSendToPrinter = True And gstrSendToPrinterName <> "(Pitney Bowes)" Then
                 mobjWordSendToDoc.PrintOut Background:=False
             End If
                  'don't merge to a doc but print (merge to printer)
         ElseIf gblnSendToDoc = False And gblnSendToPrinter = True And gstrSendToPrinterName <> "(Pitney Bowes)" Then
            .Destination = wdSendToPrinter
         End If
         If gblnSendToEmail = True Then
            .MainDocumentType = wdEMail
            .Destination = wdSendToEmail
            .MailAddressFieldName = gstrSendToEmailAddressFieldName
            .MailSubject = gstrSendToEmailSubject
            .MailFormat = gbytSendToEmailFormat
            .MailAsAttachment = gblnSendToEmailAsAttachment
         End If
          '        If gblnSendToFax Then
          '            .MainDocumentType = wdFax
          '            .Destination = wdSendToFax
          '            .Execute
          '        End If
                  'save and close the destination doc
                  'mobjWordMainDoc.Close wdSaveChanges
         mobjWordMainDoc.Close SaveChanges:=wdDoNotSaveChanges
         If gstrSendToDocName <> "" Then mobjWordSendToDoc.SaveAs (gstrSendToDocName)

     End With
     If gblnLogUpdate = True Then Call MwLogUpdate
     If gblnLogInsert = True Then Call MwLogInsert
     MwMergeExecute = True
     On Error Resume Next
              'close word if user isn't editing the doc
     If gblnSendToDocAndEdit = False Then mobjword.Quit SaveChanges:=wdDoNotSaveChanges
     Set mobjWordMainDoc = Nothing
     Set mobjWordSendToDoc = Nothing
     Set mobjword = Nothing
     Exit Function
     If Err = 3262 Then
         MsgBox "The mail merge data source is already in use, it " _
                  & "may be in use by another mail merge document.  Please " _
                  & "insure that Microsoft Word doesn't already have an open " _
                  & "mail merge document and try this operation again.", vbOKOnly, gstrAppName
         MwMergeExecute = False
         Resume Exit_MwMergeExecute
     End If
     LogErrorToTable Err.Number, Err.Description, "MwMerge", "MwMergeExecute", Erl
     Resume Exit_MwMergeExecute
          End Function

Open in new window

Juan VelasquezAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Try this line.
mobjWordSendToDoc.ExportAsFixedFormat OutputFileName:= "Filename.pdf", ExportFormat:= wdExportFormatPDF, OpenAfterExport:=False

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
You don't need the PDF addin.  PDF is a native format for word 2007:

Sub Convert_2_PDF()

ActiveDocument.ExportAsFixedFormat OutputFileName:= _

ActiveDocument.Path & "\" & ActiveDocument.Name & ".pdf", ExportFormat:= _

wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:= _

wdExportOptimizeForPrint, Range:=wdExportAllDocument, _

Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _

CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _

BitmapMissingFonts:=True, UseISO19005_1:=False

End Sub

Hammo777, please do not simply plagurize content. If you find code on the internet that you think would be useful, link to it or at least cite it as a reference.

Note: The code I posted does basically the same thing. Most of those options are the default and are not needed explicitly.
Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

Welcome to EE, by the way, and good luck on your first 10,000 points.
Juan VelasquezAuthor Commented:
Thanks for the help on the syntax
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.