Adding sections from one doc to another

I am putting together a proof of concept for my customer; they have multiple word docs that are currently being merged correctly. In some cases they would like the results of multiple docs to end up in one document (copy / paste). I have written the code based on examples here on the site; however I am now receiving an error when attempting to save the current document, after sections have been added.

I am running aspose word 1.6

Here is a section of code:

Dim i As Integer
For i = 1 To Doc2.Sections.Count
Dim mySection As Section = Doc2.Sections(i - 1)
Doc2.Sections.RemoveAt(i - 1)
doc.Sections.Add(mySection)
Next i

doc.Save(FilePath & “Quote_” & MyQuoteNumber & “.doc”)

This is the error that I am seeing:

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Thanks in advance for any pointers…
Mike

I don't think this is a safe loop, I'd suggest you restructure it to something like this:

while Doc2.Sections.Count > 0
Dim mySection as Section = Doc2.Sections(0)
Doc2.Sections.RemoveAt(0)
Doc.Sections.Add(mySection)
end

If that does not help then email your document to me to word@aspose.com.