knly5292
09-14-2012, 09:07 AM
Hello,
I've used the ExportAsFixedFormat function to convert a saved Word document to PDF. It works great on my computer, but when I ran it on another computer it crashed.
Here's the code
Private Sub ConvertToPDF(ByVal Doc As Word.Document, ByVal App As Word.Application, ByRef Template As clsTemplate)
Dim DocName As String 'The name of the document
DocName = Doc.Name
'Remove word document extention from pdf file name
If InStr(1, DocName, ".docx") > 0 Then
DocName = Replace(DocName, ".docx", "")
ElseIf InStr(1, DocName, ".doc") > 0 Then
DocName = Replace(DocName, ".doc", "")
End If
Template.PDFPath = Doc.Path & "\" & DocName & ".pdf"
Doc.ExportAsFixedFormat OutputFileName:=Template.PDFPath, ExportFormat:= _
wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:=wdExportOptimizeForPrint, Range:=wdExportAllDocument, _
Item:=wdExportDocumentContent, IncludeDocProps:=True
End Sub
It'd be great if someone can tell me why it doesn't work on another computer.
Thanks
I've used the ExportAsFixedFormat function to convert a saved Word document to PDF. It works great on my computer, but when I ran it on another computer it crashed.
Here's the code
Private Sub ConvertToPDF(ByVal Doc As Word.Document, ByVal App As Word.Application, ByRef Template As clsTemplate)
Dim DocName As String 'The name of the document
DocName = Doc.Name
'Remove word document extention from pdf file name
If InStr(1, DocName, ".docx") > 0 Then
DocName = Replace(DocName, ".docx", "")
ElseIf InStr(1, DocName, ".doc") > 0 Then
DocName = Replace(DocName, ".doc", "")
End If
Template.PDFPath = Doc.Path & "\" & DocName & ".pdf"
Doc.ExportAsFixedFormat OutputFileName:=Template.PDFPath, ExportFormat:= _
wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:=wdExportOptimizeForPrint, Range:=wdExportAllDocument, _
Item:=wdExportDocumentContent, IncludeDocProps:=True
End Sub
It'd be great if someone can tell me why it doesn't work on another computer.
Thanks