Solved

Append word Documents

Posted on 2006-06-23
23
9,245 Views
Last Modified: 2008-01-09
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
Comment
Question by:prya
  • 13
  • 10
23 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
Comment Utility
You need something like this:

ActiveDocument.Range.Bookmarks("\EndOfDoc").Range.InsertFile "C:\MyFolder\doc2.doc"
 
0
 

Author Comment

by:prya
Comment Utility
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
 
LVL 76

Expert Comment

by:GrahamSkan
Comment Utility
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
 

Author Comment

by:prya
Comment Utility
How to merge two word documents using C# pls help me immidiate.view the full procedure
thanx
0
 
LVL 76

Expert Comment

by:GrahamSkan
Comment Utility
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
 

Author Comment

by:prya
Comment Utility
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
 
LVL 76

Expert Comment

by:GrahamSkan
Comment Utility
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
 

Author Comment

by:prya
Comment Utility
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
 
LVL 76

Expert Comment

by:GrahamSkan
Comment Utility
XLS? They were Word documents to start with, so I gave you some Word coding. Have you tried it with Word documents?
0
 

Author Comment

by:prya
Comment Utility
I want to merge two excel files  into one programmatically.
0
 

Author Comment

by:prya
Comment Utility
How can i merge framed word document programmatically.
pls help me
priya
thanx
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 76

Expert Comment

by:GrahamSkan
Comment Utility
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
 

Author Comment

by:prya
Comment Utility
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
 

Author Comment

by:prya
Comment Utility
I'm using insertbreak like this" WRange.InsertBreak(ref wdPageBreak);"
0
 
LVL 76

Expert Comment

by:GrahamSkan
Comment Utility
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
 

Author Comment

by:prya
Comment Utility
I have uploaded the documents & copied the URL from this question.
priya
thanks
0
 
LVL 76

Expert Comment

by:GrahamSkan
Comment Utility
OK priya,
It's next on my list. I must have a sleep now. Thanks for your patience.
0
 

Author Comment

by:prya
Comment Utility
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
 

Author Comment

by:prya
Comment Utility
Hi, Does anyone know how to merge multiple excel sheets into one sheet programmatically? help immidiate
prya
thanks
0
 
LVL 76

Expert Comment

by:GrahamSkan
Comment Utility
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
 

Author Comment

by:prya
Comment Utility
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
 

Author Comment

by:prya
Comment Utility
How to export crystal report to xml format programmatically using dot net?
can somebody help me as soon as possible?
thanx
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 125 total points
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now