none
Insert file into new Word document RRS feed

  • Question

  • I have a list of RTF files that I want to insert, one by one, into a new Word document, using VB.NET. In addition, I want to insert a paragraph before each inserted file that contains the title of the file. I've figured out how to insert all of the files, but I'm stumped on controlling the insertion point by Range or Selection to get one new paragraph before each inserted file. Help, please! Thanks!
    Friday, May 4, 2012 8:23 PM

Answers

  • I don't know about vb.net but in vba if you set the range to the end  of the document at the start of each loop and insert the file at the range, the file is inserted after the range, so you can then add the title to the same range e.g.

    Set oRng = ActiveDocument.Range
    oRng.Start = ActiveDocument.Range.End
    oRng.InsertFile strFilename
    oRng.Text = "This is the title" & vbCr

    If vb.net puts the file IN the range, then set the end of the range to the start of the range before inserting the paragraph.

    The bigger problem is where you get the title from.


    Graham Mayor - Word MVP
    www.gmayor.com

    • Marked as answer by DRMacy55 Friday, May 11, 2012 7:18 PM
    Saturday, May 5, 2012 2:35 PM