Word Docs to HTML converter

How to convert a html file to a word doc files programmically?
How to combine two word doc files to one word doc file?

I want a full description how to do it.
Thanks alot.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Use Ole Automation
Create a Word Object

For your first problem
Programmatically open the HTML file in Word.

Invoke the save method and save it as Word Doc.

Second problem

Open the first file

Programmatically merge the other.

To get the codes record a macro and do it manually then convert it.

If you want the exact code let me know!

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial

The verbose information as requested.

Create a new VB project and add in a reference to Word 8.0 Automation Library.  The below code is fully commented and demonstrates how to achieve the full approach soley within VB.

Copy this code and place under a Command1_Click event on a temp form to see how it works.  Please remember to change the document names used to ones that you have.  This example shows to different sections - one converting HTML to word documents and the other merging it.  

'************** CODE START ***********
Dim objWord As Word.Application
Dim objWordDoc_One As Word.Document
Dim objWordDoc_Two As Word.Document
Dim objWordDoc_Three As Word.Document
Dim objWordFileConvertor As Word.FileConverter

'Open an instance of Word - modify to use existing
Set objWord = New Word.Application
objWord.Visible = True

'Load the html document.  Modify the filename to point to an existing html document to convert
Set objWordDoc_One = objWord.Documents.Open(filename:="h:\ss\html document.html")

'Modify the file format when saving
objWordDoc_One.SaveAs filename:="h:\ss\html document.doc", FileFormat:=0
Set objWordDoc_One = Nothing

MsgBox "The HTML document has been loaded and saved as a standard word document"

'Load the first source document and save as the target merge document
Set objWordDoc_One = objWord.Documents.Open(filename:="h:\ss\html document.doc")
objWordDoc_One.SaveAs filename:="h:\merged document.doc"

'Now load the other document to be merged
Set objWordDoc_One = objWord.Documents.Open(filename:="h:\ss\word document.doc")

'Merge this into the merge document created above
objWordDoc_One.Merge "h:\ss\merged document.doc"

Set objWordDoc_One = Nothing
Set objWord = Nothing

'************** CODE END ***********

If you require any further help please let me know.
lll112Author Commented:
Thanks for your help.
May I have your source code?
Also, can you write down all the procedures in detail.

Thanks again.
Thanks for accepting my answer. I think SteveStringer has given the complete code.

Anyway I'll also post my solution soon (It will be almost same like SteveStringer's)
For Both these tasks you have to set the reference to Word Object Library. To do this:

Choose Project->References-> Microsoft Word 8.0 Object Library (for Office 97)
                        Microsoft Word 9.0 Object Library (for Office 2000)


Saving HTML File AS Word Document

Create a form and put a command button named Command1 and copy this code

The Location, Source, Target are hardcoded you have to change them according to your requirements.

Private Sub Command1_Click()
    Dim oWord As Word.Application
    Dim oSourceHTML As Word.Document
    Dim cLocation As String
    Dim cSourceFile As String
    Dim cTargetFile As String
    cLocation = "C:\Temp\"
    cSourceFile = "q125967.html"
    cTargetFile = "q125967.doc"
    ' Create a word object instance
    Set oWord = New Word.Application
    ' Open the HTML File
    Set oSourceHTML = oWord.Documents.Open(FileName:=cLocation + cSourceFile)
    ' Save it as Word document

    oSourceHTML.SaveAs FileName:=cLocation + cTargetFile, FileFormat:= _
        wdFormatDocument, LockComments:=False, Password:="", AddToRecentFiles:= _
        True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:= _
        False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
    'Close the saved document
    ' Close Word
    'Clear the variables
    Set oSourceHTML = Nothing
    Set oWord = Nothing

    MsgBox "Finished"

End Sub


Merging Two Files

Create a form and put a command button named Command2 and copy & Paste this code

The Location, File1, File2 Target are hardcoded you have to change them according to your requirements.

Private Sub Command2_Click()
    Dim oWord As Word.Application
    Dim oMergeFile As Word.Document
    Dim cLocation As String
    Dim cFile1 As String
    Dim cFile2 As String
    Dim cTargetFile As String
    cLocation = "C:\Temp\"
    cFile1 = "q125967.doc"
    cFile2 = "q133163.doc"
    cTargetFile = "Merged.doc"
    Set oWord = New Word.Application
    'Open the First File
    Set oMergeFile = oWord.Documents.Open(FileName:=cLocation + cFile1, ConfirmConversions:=False, _
        ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _
        PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
        WritePasswordTemplate:="", Format:=wdOpenFormatAuto)
    'Save the first file as merged file name
    oMergeFile.SaveAs FileName:=cLocation + cTargetFile, FileFormat:=wdFormatDocument, _
         LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword _
        :="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
        SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
    'Here I am using Insert File Method or else you can ue the "Merge" method as well
    'Navigate to the end
    oWord.Selection.EndKey Unit:=wdStory
    'Insert The second File
    oWord.Selection.InsertFile FileName:=cLocation + cFile2, Range:="", _
        ConfirmConversions:=False, Link:=False, Attachment:=False
    Set oMergeFile = Nothing
    Set oWord = Nothing
    MsgBox "Finished"
End Sub


Better way to learn this is record a macro in word and convert the code to VB.

If you want the complete code in VB format send a mail to ee_support@sivaram.8m.com
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.