Hi,

I want to convert my word file to pdf file in vb6.
source code will be appreciated.

so far, i have tried with below code also.

Private Sub Convert_WordDoc_to_PDF(DocPath As String, sDestsPDFFile As String)
'Dim worddoc As New Word.Application
Dim worddoc As Object
Set worddoc = CreateObject("Word.Application")

Dim x As String
Dim doc As Document
On Error GoTo Errhnd
x = DocPath
Set doc = worddoc.Documents.Open(x) '-----------open the docx


'now docx file is already open . so  now it is time to export into PDF Format

 doc.ExportAsFixedFormat OutputFileName:= _
        x & "/" & sDestsPDFFile, ExportFormat:=wdExportFormatPDF, _
        OpenAfterExport:=True, OptimizeFor:=wdExportOptimizeForPrint, Range:= _
        wdExportAllDocument, From:=1, To:=1, Item:=wdExportDocumentContent, _
        IncludeDocProps:=True, KeepIRM:=True, CreateBookmarks:= _
        wdExportCreateNoBookmarks, DocStructureTags:=True, BitmapMissingFonts:= _
        True, UseISO19005_1:=False
    doc.Close
    Exit Sub
Errhnd:
MsgBox (err.Description)
Set worddoc = Nothin
End Sub

but gives error at doc.ExportAsFixedFormat line that 'Method or data member not found.'

Thanks

Hello All,

I got the solution. please find below code to convert word file to pdf file.

Private Sub Convert_WordDoc_to_PDF(DocPath As String, sDests As String, sDestsPDFFile As String)

On Error GoTo ErrorHandler
Dim objWord As Word.Application
Dim objWordDoc As Word.Document

Set objWord = CreateObject("Word.Application")
objWord.Visible = True
Set objWordDoc = objWord.Documents.Open(DocPath)
objWordDoc.ExportAsFixedFormat OutputFileName:= _
        sDests & sDestsPDFFile, 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
Exit Sub

ErrorHandler:
    MsgBox err.Description, vbInformation, "Error Creating PDF"
End Sub

one must have to install microsoft office add on for export if not installed. you can download and install from below link :

Click Here

Thanks

Hi I have installed the microsoft office add on but do we have to add it to our project? I'm getting error at Word.Application. Please give a solution.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.