Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

combining 2 doc file to single doc file

Status
Not open for further replies.

murushanmugham

IS-IT--Management
Jan 2, 2003
33
How can i combine two word files into a single word file using any method. I want to know how to to combine two existing documents into a single doc file. Any Ideas | code samples ?

Murushan
 
Easy way is to use the VBA generated by VBA macro recorder. You will need to reference the Word library first.

Dim WP As Word.Application
Set WP = CreateObject("word.Application")


Then use the VBA from the macro, referring to the WP object that you've just opened.

Don't forget to Quit the application and set the reference to Nothing when you're done

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'

for steam enthusiasts
 
thanks

"Then use the VBA from the macro, referring to the WP object that you've just opened.

Don't forget to Quit the application and set the reference to Nothing when you're done "

i need complete code please ..(Example Code)

thanks in advance

murushan

 
thnaks for your advoce..

i am expereinced in Vb..
but vb & word application .... new ...!!!

help needed this ..

murushan

 
No...

give some idea please..

thanks in advance ..

murushan
 
OK, here is some pseudocode:

Create the Word object (as described by John above)

Create and open the document...
Dim z As Word.Document
Set z = Word.Documents.Open("C:\YourDoctoCopyFrom.doc")

Select the whole text in the document and copy it (the commands for this can be found in Word VBA by recording a macro (again, as described by John))

Quit and set word object to nothing...
z.Close
WP.Quit
Set WP = Nothing

Now you have the text you want to combine into the new document.

Open the document you want to paste into using the methods described in this post and John's (you can use the same Dimmed variables but just change how they are assigned).

Go to the end of the new document and paste all of the data in. Again, this can be found by recording a macro in word.

Add the line ActiveDocument.Save before you close this time as the doc has been changed and will not close properly if not saved in this way. Quit the application and set the reference to nothing as described in the first part of my post.

Hope this is a helps to you.

Harleyquinn

---------------------------------
For tsunami relief donations
 
open different files: using the following statement
==================================
Dim wp As Word.Application
Set wp = CreateObject("word.application")
Dim z As Word.Document
Set z = Word.Documents.Open("d:\news\sample.doc")
Documents.Add Template:="d:\news\sample.doc", _
NewTemplate:=False
Documents.Add Template:="e:\shan\itshan05.doc", _
NewTemplate:=False
Documents.Add Template:="e:\shan\iocl brochure.doc", _
NewTemplate:=False
Documents.Add Template:="e:\shan\citi-cancel.doc", _
NewTemplate:=False

===============================================

how to combine all four docuemnts in to a single document file name new.doc

thanks in advance

murushan
 
why go to code?

The question just asks about combining 2 .doc files into one .doc file using any method.

Isn't this what the insert file feature within Word is for? Use it, then use SaveAs into a different file name.

...or am I misreading the original question

 
That is a fantastic call Jonsi!!!! [smile]
And if he does want to do it in code I've just recorded a macro doing it and it's pretty simple to port into VB6. [smile]

Harleyquinn

---------------------------------
For tsunami relief donations
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top