Results 1 to 7 of 7

Thread: [RESOLVED] Merging two .doc files

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2008
    Posts
    75

    Resolved [RESOLVED] Merging two .doc files

    Hi everyone,

    I wrote an application which converts .doc files into .pdf. Now I would like to add one more thing:
    before converting the .doc file, which is selected by the user, I would like to add the content of an other (default) .doc file, which will not be selected by the user but the directory where the file is will be already in the code, in front of the file selected by the user. So after the two files are merged I will have the merged file converted to PDF.

    I hope I have been clear enough.

    Regards,

    A.

  2. #2
    Fanatic Member amrita's Avatar
    Join Date
    Jan 2007
    Location
    Orissa,India
    Posts
    888

    Re: Merging two .doc files

    Use
    Code:
    WordObject.Documents.ADD("1st file name with path")
    and then


    Code:
    WordObject.Selection.InsertFile(filename:=2ndfile_FullName, Range:="", ConfirmConversions:=False, Link:=False, Attachment:=False)
    thanks
    amrita

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2008
    Posts
    75

    Re: Merging two .doc files

    Hi Amrita.

    Thanks for the reply. How should I declare "WordObject"? It keeps telling me "Name WordObject is not declared"

    Thank you,

    A.

  4. #4
    Fanatic Member amrita's Avatar
    Join Date
    Jan 2007
    Location
    Orissa,India
    Posts
    888

    Re: Merging two .doc files

    Code:
    Dim wordObject as Object
    
    wordObject = CreateObject("Word.Application")
    thanks
    amrita

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Mar 2008
    Posts
    75

    Re: Merging two .doc files

    Cool now it compiles with no errors!
    Unfortunately the program does not seem working. Nothing happens after i click the button!
    Here is the code:
    Code:
    Dim wordObject As Object
            wordObject = CreateObject("Word.Application")
            wordObject.Documents.ADD("C:\hello.doc")
            wordObject.Selection.InsertFile(filename:=TextBox1.Text, Range:="", ConfirmConversions:=False, Link:=False, Attachment:=False)
    Thank you,

    A.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Mar 2008
    Posts
    75

    Re: Merging two .doc files

    I did it by using the following code:

    Code:
            Dim wordObject As Object
            wordObject = CreateObject("Word.Application")
            wordObject.Documents.ADD(TextBox1.Text)
            wordObject.Selection.InsertFile(filename:="C:\hello.doc", Range:="", ConfirmConversions:=False, Link:=False, Attachment:=False)
            wordObject.activedocument.saveas("c:\hellomerged.doc")
            MsgBox("ok")
    Now I noticed that in the running processes there is the "WINWORD.exe" which is running in background. I need to figure out how to terminate it from the vb code.
    I tried
    Code:
    wordObject.activedocument.close("c:\hellomerged.doc")
    but doesn't work

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Mar 2008
    Posts
    75

    Re: Merging two .doc files

    Solved!
    I just add the following line:

    Code:
     wordObject.activedocument.close()
    Thank you!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width