LSpiker
asked on
How do I save a word doc to pdf from access using vb?
This I'm sure isn't hard but I can't find any documentation on it. I'm using Access 2007, Word 2007. They are both set up to write to pdf. I have data dumping into Word but now I must save the word document as a pdf. All of this under one buttion. Everything is working fine except how to covert my finished Word doc to pdf. Any Help?
ASKER
Even if that option exists on Word? I can press a button and create a pdf from word. Is there a reason I can't script that same command to Word?
You can install the PDF add in for Office 2007.
http://www.microsoft.com/downloads/details.aspx?FamilyID=f1fc413c-6d89-4f15-991b-63b07ba5f2e5&displaylang=en
Then you have an option under the Office button to Save as a PDF.
;-)
JeffCoachman
untitled.JPG
http://www.microsoft.com/downloads/details.aspx?FamilyID=f1fc413c-6d89-4f15-991b-63b07ba5f2e5&displaylang=en
Then you have an option under the Office button to Save as a PDF.
;-)
JeffCoachman
untitled.JPG
ooops, sorry LSpiker I mis-read your post.
Basically you have to tack some code on to open the Word Doc in the background and save the file as a PDF
Something roughly like this "Air Code:
Dim objWord As Object
Set objWord = CreateObject("word.applica tion")
objWord.Documents.Open FileName:="C:\YourFolder\W ordPDF.doc x"
objWord.Visible = True
objWord.ExportAsFixedForma t OutputFileName:="C:\YourFo lder\PDF22 .pdf", ExportFormat:=wdExportForm atPDF
objWord.Quit.wdSaveChanges
Set objWord = Nothing
The above code probably wont work exactly.
Please click the "Request Attention" Button/Link and ask that the Word Zone be added to this question.
Perhaps a Word Expert can flesh this out for you.
;-)
JeffCoachman
Basically you have to tack some code on to open the Word Doc in the background and save the file as a PDF
Something roughly like this "Air Code:
Dim objWord As Object
Set objWord = CreateObject("word.applica
objWord.Documents.Open FileName:="C:\YourFolder\W
objWord.Visible = True
objWord.ExportAsFixedForma
objWord.Quit.wdSaveChanges
Set objWord = Nothing
The above code probably wont work exactly.
Please click the "Request Attention" Button/Link and ask that the Word Zone be added to this question.
Perhaps a Word Expert can flesh this out for you.
;-)
JeffCoachman
Convert Word to PDF using VBA
Word 2007 has a new method - Document.ExportAsFixedForm at, which saves the document as PDF or XPS format.
The following code will save the current document as PDF in the same path
Sub Convert_2_PDF()
ActiveDocument.ExportAsFix edFormat OutputFileName:=Left(Activ eDocument. Name, Len(ActiveDocument.Name) - 5) & "\" & ActiveDocument.Name & ".pdf", ExportFormat:=wdExportForm atPDF, OpenAfterExport:=False, OptimizeFor:=wdExportOptim izeForPrin t, Range:=wdExportAllDocument , Item:=wdExportDocumentCont ent, IncludeDocProps:=True, KeepIRM:=True, CreateBookmarks:=wdExportC reateNoBoo kmarks, DocStructureTags:=True, BitmapMissingFonts:=True, UseISO19005_1:=False
End Sub
See: http://msdn.microsoft.com/en-us/library/bb256835.aspx
Word 2007 has a new method - Document.ExportAsFixedForm
The following code will save the current document as PDF in the same path
Sub Convert_2_PDF()
ActiveDocument.ExportAsFix
End Sub
See: http://msdn.microsoft.com/en-us/library/bb256835.aspx
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hello_Everybody has the type of solution I'm looking for but I'm not getting it to work properly.
Whats the problem?
ASKER
Hello everybody: Sorry for the time lapse. I've been bounced around a few other projects and finally got back to this one. OK your last solution on the msdn library looks like exactly what I'm looking for.
I am having a little trouble implementing it however. Step one I have we are good with referencing. Step two which imports the Microsoft.Office.Interop.W ord peice I'm not getting. Where does this live in my code? or is this an external piece?
I am having a little trouble implementing it however. Step one I have we are good with referencing. Step two which imports the Microsoft.Office.Interop.W
ASKER
Also on the code in your heading called "Runtime err 429" "Convert Word to PDF using VBA" when I run this from Access I get an error that states "ActiveX componenet can't create object. The following is what I have:
ActiveDocument.ExportAsFix edFormat "C:\Program Files\MCSGAPPS\StrategicRe viewSLUG.p df", wdExportFormatPDF, False, wdExportOptimizeForPrint, wdExportAllDocument, wdExportDocumentContent, True, True, wdExportCreateNoBookmarks, True, True, False
ActiveDocument.ExportAsFix
ASKER
I have also tried this: and got "Runtime Err 438 Object doesn't support this property or method"
Dim objWord As Object
Set objWord = CreateObject("word.applica tion")
objWord.Documents.Open FileName:="C:\Program Files\MCSGAPPS\StrategicRe viewSLUG.d ocx"
objWord.Visible = True
ocuments and Settings\fhi9283\Desktop\Y ippie.pdf" , ExportFormat:=wdExportForm atPDF
objWord.ExportAsFixedForma t OutputFileName:="C:\Docume nts and Settings\fhi9283Desktop\Yi ppie.pdf", ExportFormat:=wdExportForm atPDF
objWord.Quit.wdSaveChanges
Set objWord = Nothing
Dim objWord As Object
Set objWord = CreateObject("word.applica
objWord.Documents.Open FileName:="C:\Program Files\MCSGAPPS\StrategicRe
objWord.Visible = True
ocuments and Settings\fhi9283\Desktop\Y
objWord.ExportAsFixedForma
objWord.Quit.wdSaveChanges
Set objWord = Nothing
ASKER
SOLUTION!!!!!!!!!!!!!!!!!! With the information recieved I was able to track down/ work and redevelop. this is for Future users.....
Dim objWord As Object
Dim frmt
Set objWord = CreateObject("word.applica tion")
objWord.Documents.Open Filename:="C:\XYZ.docx"
objWord.ActiveDocument.Exp ortAsFixed Format OutputFileName:= _
"C:\XYZ\Yippie.pdf", ExportFormat:=wdExportForm atPDF, _
OpenAfterExport:=False, OptimizeFor:=wdExportOptim izeForPrin t, Range:= _
wdExportAllDocument, from:=1, To:=1, Item:=wdExportDocumentCont ent, _
IncludeDocProps:=True, KeepIRM:=True, CreateBookmarks:= _
wdExportCreateNoBookmarks, DocStructureTags:=True, BitmapMissingFonts:= _
True, UseISO19005_1:=False
objWord.Quit
Set objWord = Nothing
Dim objWord As Object
Dim frmt
Set objWord = CreateObject("word.applica
objWord.Documents.Open Filename:="C:\XYZ.docx"
objWord.ActiveDocument.Exp
"C:\XYZ\Yippie.pdf", ExportFormat:=wdExportForm
OpenAfterExport:=False, OptimizeFor:=wdExportOptim
wdExportAllDocument, from:=1, To:=1, Item:=wdExportDocumentCont
IncludeDocProps:=True, KeepIRM:=True, CreateBookmarks:= _
wdExportCreateNoBookmarks,
True, UseISO19005_1:=False
objWord.Quit
Set objWord = Nothing
ASKER
Very good information and with the info from other folks and research and trial and error I found the entire solution and posted it. Thank you specialists, I wouldn't have been able to finish it on my own.
Try this: http://www.verypdf.com/artprint/word-ole-visual-basic-sdk-sample.htm
Or this: http://www.print-driver.com/sdk/examples/vb6/index.html.
There are many more just search for a Pdf SDK.