I've got this code below which creates a PDF document. The error message appears saying I'm unable to open the document because:
VBA Code:
The code works when I change the FilePath from ".pdf" to ".docx"
Code:
it is either not a supported file type or because the file has been damaged
VBA Code:
Code:
Private Sub Command273_Click()
Dim wdApp As Word.Application, wdDoc As Word.Document
FileName = [URN] & " - Agreement X34"
FilePath = "\Backup\Agreements\Leads\" & FileName & ".pdf"
On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then 'Word isn't already running
Set wdApp = CreateObject("Word.Application")
End If
On Error GoTo 0
Set wdDoc = wdApp.Documents.Open("\Backup\Agreements\Leads\Agreement X34.docx")
wdApp.Visible = False
wdDoc.FormFields("ReferenceID").Result = Nz(Me!txtPDFReference, "")
wdDoc.FormFields("txtCompanyName").Result = Nz(Me!BusinessName, "")
wdDoc.FormFields("txtAddressLine1").Result = Nz(Me!AddressLIne1, "")
wdDoc.FormFields("txtAddressLine2").Result = Nz(Me!AddressLine2, "")
wdDoc.FormFields("txtPostCode").Result = Nz(Me!PostCode, "")
wdDoc.SaveAs2 FilePath
End Sub
The code works when I change the FilePath from ".pdf" to ".docx"