Tuesday, February 1, 2011

How to Convert Word document to html/pdf ??

How to Convert Word document to html/pdf ??

ConvertDOCtoHTMLPDF("C:\Test1.docx","Pdf")
ConvertDOCtoHTMLPDF("C:\Test1.docx","html")
  
Function ConvertDOCtoHTMLPDF(SrcFile, Format)
   Dim fso, oFile, FilePath, myFile
   Set fso = CreateObject( "Scripting.FileSystemObject" )
   Set oFile = fso.GetFile(SrcFile)
   FilePath = oFile.Path
    
   Dim oWord
   Set oWord = CreateObject( "Word.Application" )
   oWord.Documents.Open FilePath
   If ucase(Format) = "PDF" Then
       myFile = fso.BuildPath (ofile.ParentFolder ,fso.GetBaseName(ofile) & ".pdf")
       oWord.Activedocument.Saveas myfile, 17
   elseIf ucase(Format) = "HTML" Then
       myFile = fso.BuildPath (ofile.ParentFolder ,fso.GetBaseName(ofile) & ".html")
       oWord.Activedocument.Saveas myfile, 8
   End If
   oWord.Quit
   Set oWord = Nothing
   Set fso = Nothing
   Set oFile = Nothing
End Function

1 comment:

  1. Hello Raghuraj

    This script is not working.
    Can you please check?


    Thanks.
    AJ

    ReplyDelete