[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 9282
  • Last Modified:

Append word Documents

I have doc1.doc and doc2.doc... i want to open using the Word Document & i want to beable to take the contents of doc2 and append it to the bottom of doc1 with code.. how would i go about doing this?

Thank you.
0
prya
Asked:
prya
  • 13
  • 10
1 Solution
 
GrahamSkanRetiredCommented:
You need something like this:

ActiveDocument.Range.Bookmarks("\EndOfDoc").Range.InsertFile "C:\MyFolder\doc2.doc"
 
0
 
pryaAuthor Commented:
how can i use ""ActiveDocument.Range.Bookmarks("\EndOfDoc").Range.InsertFile "C:\MyFolder\doc2.doc""" ? i could not understand this.please help me .pls tell me how can i merge or append word documents? tell me full procedure .
I'm using crystal report9.i'm exporting crystal report to word document programmatically.So i have many documents.now i want to bind all of documents in one document.so how can i do this pls help me .tell me full code pls.
thanx in advance
priya
0
 
GrahamSkanRetiredCommented:
That is Word VBA, the first programming language that comes to mind for Word.
It would need to go in a Sub, so:

Sub InsertOneFile()
   ActiveDocument.Range.Bookmarks("\EndOfDoc").Range.InsertFile "C:\MyFolder\doc2.doc"
End sub

Open the first document, then run the code.

For your extra requirement to merge several files together, I suggest that you put all the files into a single folder, and run this macro.

Sub InsertFiles()
    Dim strFileName As String
    Dim rng As Range
   Dim Doc As Document
    Const strPath = "C:\Documents and Settings\User Name\My Documents" 'adjust as necessary
    strFileName = Dir$(strPath & "\*.doc")
    Set Doc = Documents.Open(strPath & "\" & strFileName)
    Do
        strFileName = Dir$()
        If strFileName = "" Then
            Exit Sub
        End If
        Set rng = Doc.Bookmarks("\EndOfDoc").Range
        rng.InsertFile strPath & "\" & strFileName
    Loop Until strFileName = ""
End Sub


0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
pryaAuthor Commented:
How to merge two word documents using C# pls help me immidiate.view the full procedure
thanx
0
 
GrahamSkanRetiredCommented:
I don't use C#, so I can't convert from VBA .

I suppose that you will need to set references, as here:
http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_20978556.html

However, this site thinks it might be difficult:
http://msdn.microsoft.com/msdnmag/issues/05/02/EndBracket/
0
 
pryaAuthor Commented:
I want to merge over a hundred Word documents into one document without doing an Insert for each file within Word. Is there an easy way to accomplish this task? i want to do this programmatically
0
 
GrahamSkanRetiredCommented:
It is easy in VB or VBA. I have shown you how to do it in VBA. If you have Word, you can run the VBA code that I posted. If  you need further help with that, let us know here.

If you don't want to use VBA, you will have to use COM to manipulate the Word object model. I could show you how to do that with VB6 or VBScript.

If you know how to use C#, which I don't, the two links should help you to do it, though the second one does explain that C# is not designed to fit with the Office object models, so it might be difficult.

If you don't know how to use C#, but still want to use it, perhaps you should post a pointer question here:

http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/

remembering to post a link back to this question.
0
 
pryaAuthor Commented:
this programme is not working .pls tell me more about this .you can tell me in Vb .pls help me.
I want to merge many xls files into one programmatically.pls help me how can i do this as soon as possible.
thanx
0
 
GrahamSkanRetiredCommented:
XLS? They were Word documents to start with, so I gave you some Word coding. Have you tried it with Word documents?
0
 
pryaAuthor Commented:
I want to merge two excel files  into one programmatically.
0
 
pryaAuthor Commented:
How can i merge framed word document programmatically.
pls help me
priya
thanx
0
 
GrahamSkanRetiredCommented:
Hello priya,

I have already shown you how to merge Word documents. I don't know what you mean by a framed Word document.

Merging Excel files could be as simple as importing the separate spreadsheets, but it is a separate subject.

I realise that English is probably not your first language, and I am sure that your English is better than my knowledge of your language, but I do need to understand properly what you need. Do you have a friend who is better at English who can help you?

Regards, Graham
0
 
pryaAuthor Commented:
my question is clear for you .I have done this.But problem is different.I'm working on crystal report9.I exported report from crystal report to word document having its format .now i want to merge or append many word document into one programmatically.By that programme when i use "insertbreak" there is an error occured " This method or property is not available because the object refers to a framed paragraph" because report document is framed .this is my meaning.
priya
thanx
0
 
pryaAuthor Commented:
I'm using insertbreak like this" WRange.InsertBreak(ref wdPageBreak);"
0
 
GrahamSkanRetiredCommented:
OK.
Can you upload 2 of the documents here: www.ee-stuff.com . Copy the URL from this question so that they can be found.

Tell us back here when that is done.

Regards
0
 
pryaAuthor Commented:
I have uploaded the documents & copied the URL from this question.
priya
thanks
0
 
GrahamSkanRetiredCommented:
OK priya,
It's next on my list. I must have a sleep now. Thanks for your patience.
0
 
pryaAuthor Commented:
hi does anyone know how to merge 2 excell files in to one files
instead have to copy all of them and paste it to the other

 I am trying to move 3 excell files into one excell file. I need the final excel sheet to not have any duplicates in one field, and to check the number in another field and only put the record ...
 I have a strange request: I have 3 excel files of 1,000 records each and the same column headers. Here's what I want to do: to merge all three files into one new file
0
 
pryaAuthor Commented:
Hi, Does anyone know how to merge multiple excel sheets into one sheet programmatically? help immidiate
prya
thanks
0
 
GrahamSkanRetiredCommented:
Thanks for that.
The input documents comprise only Frames, so the only paragraph is the mandatory last one. This last paragraph mark was being merged with the existing last paragraph. This resulted in all the frames having a common Anchor, so that each page was laid out on to of the other.
This code inserts a Next Page section break to prevent that.

Sub InsertFiles()
    Dim strFileName As String
    Dim rng As Range
    Dim Doc As Document
    Const strPath = "C:\Documents and Settings\Graham Skan\My Documents\Allwork\Experts\Priya" 'adjust as necessary
   
    Set Doc = Documents.Add
    strFileName = Dir$(strPath & "\*.doc")
    Do
        Set rng = Doc.Bookmarks("\EndOfDoc").Range
        If rng.End > 0 Then 'section break not necessary before first document.
            rng.InsertBreak wdSectionBreakNextPage
            rng.Collapse wdCollapseEnd
        End If
        rng.InsertFile strPath & "\" & strFileName
        strFileName = Dir$()
    Loop Until strFileName = ""
End Sub
0
 
pryaAuthor Commented:
I'm working on crystal report9.While exporting the report to excel, the headers are shifted.
how can i solve this problem?help pls
priya
thanks
0
 
pryaAuthor Commented:
How to export crystal report to xml format programmatically using dot net?
can somebody help me as soon as possible?
thanx
0
 
GrahamSkanRetiredCommented:
priya,

You should post one question per subject. Even with a newly opened question at or near the top of the list, no expert is likely to read down to see if there are extra queries on other technologies. As it is, this question is the 205th open question in the Programming area, so I am the only other person likely to read it at all. I responded because I know about Word which was in the title. I don't know about Crystal Reports or XML.

If you have questions on Crystal reports, post them here.
http://www.experts-exchange.com/Databases/Crystal_Reports/

Here for XML
http://www.experts-exchange.com/Web/Web_Languages/XML/

Here for Excel:
http://www.experts-exchange.com/Applications/MS_Office/Excel/


0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 13
  • 10
Tackle projects and never again get stuck behind a technical roadblock.
Join Now