• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 848
  • Last Modified:

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?
0
LSpiker
Asked:
LSpiker
  • 7
  • 4
  • 2
  • +1
1 Solution
 
hello_everybodyCommented:
There is no code to convert a Word document to a PDF file. You have to install 3rd party software, set a refrence to its library and call its functions. If you do web search you  should come up with many software you can use.
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.
0
 
LSpikerAuthor Commented:
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?
0
 
Jeffrey CoachmanCommented:
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
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
Michael VasilevskySolutions ArchitectCommented:
0
 
Jeffrey CoachmanCommented:
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.application")
objWord.Documents.Open FileName:="C:\YourFolder\WordPDF.docx"

objWord.Visible = True
objWord.ExportAsFixedFormat OutputFileName:="C:\YourFolder\PDF22.pdf", ExportFormat:=wdExportFormatPDF

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
0
 
hello_everybodyCommented:
Convert Word to PDF using VBA

Word 2007 has a new method - Document.ExportAsFixedFormat, 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.ExportAsFixedFormat OutputFileName:=Left(ActiveDocument.Name, Len(ActiveDocument.Name) - 5) & "\" & 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


See: http://msdn.microsoft.com/en-us/library/bb256835.aspx
0
 
hello_everybodyCommented:
0
 
LSpikerAuthor Commented:
Hello_Everybody has the type of solution I'm looking for but I'm not getting it to work properly.  
0
 
hello_everybodyCommented:
Whats the problem?
0
 
LSpikerAuthor Commented:
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.Word peice I'm not getting.  Where does this live in my code?  or is this an external piece?
0
 
LSpikerAuthor Commented:
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.ExportAsFixedFormat "C:\Program Files\MCSGAPPS\StrategicReviewSLUG.pdf",    wdExportFormatPDF, False, wdExportOptimizeForPrint, wdExportAllDocument, wdExportDocumentContent, True, True, wdExportCreateNoBookmarks, True, True, False
 
0
 
LSpikerAuthor Commented:
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.application")
objWord.Documents.Open FileName:="C:\Program Files\MCSGAPPS\StrategicReviewSLUG.docx"
objWord.Visible = True
ocuments and Settings\fhi9283\Desktop\Yippie.pdf", ExportFormat:=wdExportFormatPDF
objWord.ExportAsFixedFormat OutputFileName:="C:\Documents and Settings\fhi9283Desktop\Yippie.pdf", ExportFormat:=wdExportFormatPDF  
objWord.Quit.wdSaveChanges
Set objWord = Nothing
0
 
LSpikerAuthor Commented:
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.application")
objWord.Documents.Open Filename:="C:\XYZ.docx"

  objWord.ActiveDocument.ExportAsFixedFormat OutputFileName:= _
        "C:\XYZ\Yippie.pdf", ExportFormat:=wdExportFormatPDF, _
        OpenAfterExport:=False, OptimizeFor:=wdExportOptimizeForPrint, Range:= _
        wdExportAllDocument, from:=1, To:=1, Item:=wdExportDocumentContent, _
        IncludeDocProps:=True, KeepIRM:=True, CreateBookmarks:= _
        wdExportCreateNoBookmarks, DocStructureTags:=True, BitmapMissingFonts:= _
        True, UseISO19005_1:=False
   
objWord.Quit
Set objWord = Nothing
0
 
LSpikerAuthor Commented:
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.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 7
  • 4
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now