Click here to Skip to main content
15,741,531 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
I have a code to convert word document in PDF in VB 6.0 But when i try to convert it gives error invalid procedure call

What I have tried:

Dim objDoc As Object                                  
    Dim rngRange As Object                               
    Dim WordApp As Object                      
    Set objDoc = CreateObject("Word.Document")
    Set WordApp = CreateObject("Word.Application")
 With WordApp
     Set objDoc = .Documents.Open(g_strPath & "\Documents\Report.doc")

        WordApp.ActiveDocument.ExportAsFixedFormat OutputFileName:= _
        App.Path & "\Documents\Report.pdf", 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
        objDoc.PrintOut FileName = "C:\MyReport.pdf"
        Set objDoc = Nothing
        Set rngRange = Nothing
        .visible = True
end with
Updated 19-Dec-19 13:11pm
Richard MacCutchan 18-May-19 9:43am    
Where does the error occur?
djs83 20-May-19 7:14am    
When I call WordApp.ActiveDocument.ExportAsFixedFormat OutputFileName........
For this call i get error "object doesn't support this property or call"
Richard MacCutchan 20-May-19 7:53am    
Check the documentation to see which part is not valid. It may be that the ExportAsFixedFormat method does not exist, or one of the parameters is incorrect.
DerekT-P 18-May-19 13:39pm    
You're specifying both range and from / to parameters; but from / to are only relevant if the selected range is wdExportRange. At the end of the routine you're calling PrintOut with a filename parameter. You're not using a named parameter and, if you were, the parameter is named OutputFileName not FileName. The filename is only of any relevance if you set "PrintToFile" true, which you're not; so the final step just prints the document to the default printer. Now, if you have setup the default printer as PrintToPdf then that may be all you need to do, i.e. no need to attempt the previous export.
objDoc.PrintOut OutputFileName:="C:\myReport.pdf",PrintToFile:=True
djs83 20-May-19 7:17am    
I have used some bookmarks in my word document to show data. And I want to convert Whole word doc to PDF. Should I remove to/from parameters

You have to install the microsoft office add on for export, see example 2 here:
visual-basic-6 - convert Word file to Pdf file in vb6.0 [SOLVED] | DaniWeb[^]
Share this answer
Thanks for the example. It worked for me in VB6. I added a Call statement and here are the values I used...

Dim lngPageCount As Long
lngPageCount = 1
Call objDoc.ExportAsFixedFormat(strReportName & ".pdf", wdExportFormatPDF, False, _
wdExportOptimizeForPrint, wdExportAllDocument, 1, lngPageCount, _
wdExportDocumentContent, False, True, wdExportCreateNoBookmarks, True, _
True, False)
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900