Save Word As PDF (1 Viewer)

abbaddon223

Registered User.
Local time
Yesterday, 22:12
Joined
Mar 13, 2010
Messages
162
Hello all,

I'm using the below to merge from acces to word and create a new doc. All is well.

However I need to save the output file type as PDF.

When I try to change the docx to PDF, it corrupts? Can anyone help please?

Thank you in advance for any kind support.

Phil.

Dim wordApp1 As Word.Application
Dim docPath1 As String
Dim fileName1 As String
docPath1 = Application.CurrentProject.Path & "\Merges"
fileName1 = docPath1 & "\Created\Cover Letter.docx"
Set wordApp1 = New Word.Application
With wordApp1



.Documents.Add docPath1 & "\Templates\Cover Letter.Dotx" ' Where master template is with bookmarks
.Visible = True
.ActiveDocument.bookmarks.Item("CustName").Range.Text = [Title] & " " & [Forename] & " " & [Surname]
.ActiveDocument.bookmarks.Item("Company").Range.Text = [CompanyName]
.ActiveDocument.bookmarks.Item("Add1").Range.Text = [Address1]
.ActiveDocument.bookmarks.Item("Add2").Range.Text = [Address2]
.ActiveDocument.bookmarks.Item("Town").Range.Text = [Town]
.ActiveDocument.bookmarks.Item("County").Range.Text = [County]
.ActiveDocument.bookmarks.Item("Post").Range.Text = [Postcode]
.ActiveDocument.bookmarks.Item("Forename").Range.Text = [Forename]
.ActiveDocument.bookmarks.Item("Notes").Range.Text = [SpecialNotes]

.ActiveDocument.Activate
.ActiveDocument.Application.windowState = wdWindowStateNorma 'l ?
.ActiveDocument.ActiveWindow.windowState = wdWindowStateNormal '1?
.ActiveDocument.SaveAs2 (fileName1) 'probably save to docref

End With

'Print it or save it or some such thing?

wordApp1.ActiveDocument.Close
wordApp1.Quit
 

James Dudden

Access VBA Developer
Local time
Today, 06:12
Joined
Aug 11, 2008
Messages
369
Try something like this:

wordApp1.ExportAsFixedFormat YOURPath, wdExportFormatPDF, True, wdExportOptimizeForPrint, wdExportAllDocument

NB: YOURPATH should be the full path od the pdf e.g. c:\mypdf.pdf
 

Users who are viewing this thread

Top Bottom