Open word doc from Access and do a File Save as

Dear Experts

From MS Access I am looking to open an existing word document (C:\Users\XXXX\Desktop\Wordtest.docx) and with that document do a "File Save as PDF", saving the end result in another folder (C:\Users\XXXX\Desktop\Done\Result.pdf). Once done the code should close down the original word document & the PDF.

I'm using Word & Access 2010, can anybody help & can this be done when other word documents might also be open?

Many thanks
correlateAsked:
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.

GrahamSkanRetiredCommented:
Something like this:
Public Sub WordToPDF()

    'Early binding for easier development. Needs a reference to the Microsoft Word Object Library
    Dim oApp As Word.Application
    Dim doc As Word.Document
    '
    Dim strFileNamePDF As String
    Dim strFileNameWord As String
    Dim bNewWordApp As Boolean
    
     
    strFileNameWord = "C:\Users\XXXX\Desktop\Wordtest.docx"
    strFileNamePDF = "C:\Users\XXXX\Desktop\Done\Result.pdf"
    
    'try to avoid multiple instance of the Word application"
    On Error Resume Next 'temporarily supress error checking
        Set oApp = GetObject(, "Word.Application")
    On Error GoTo 0 'resume error checking
    If oApp Is Nothing Then
        Set oApp = CreateObject(Class:="Word.Application")
        bNewWordApp = True
    End If
    
    oApp.Visible = True
    
    Set doc = oApp.Documents.Add(strFileNameWord)
    doc.SaveAs2 filename:=strFileNamePDF, FileFormat:=WdSaveFormat.wdFormatPDF
    doc.Close wdDoNotSaveChanges

    If bNewWordApp Then
        oApp.Quit
    End If
End Su

Open in new window

b
0

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
correlateAuthor Commented:
Perfect, thank you very much, works a treat
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.