开发者

Combine several RTF texts into one RTF file using VBA

开发者 https://www.devze.com 2022-12-08 11:11 出处:网络
I\'m extracting \'task notes\' from MS Project using VBA and want to create a MS Word .DOC file and also copy those texts into EXCEL.

I'm extracting 'task notes' from MS Project using VBA and want to create a MS Word .DOC file and also copy those texts into EXCEL.

If you use the Notes property of the Task objects you only get 255 characters and formatting will not not be re开发者_开发百科tained. In order to keep formatting you can convert the .MPP file into .MPD and extract the notes. These notes have been stored using rtf (see PJDB.HTM look for 'sub getRtf'). This way I can extract all notes and write them into a .rtf file. If I open that file (containing multiple notes [i verified]) using MS Word I ONLY see the first note (and it has been formatted well). Info I gathered from other sites learns only ONE rtf text in a file will be handled and it is NOT trivial to join several rtf texts.

So my question is: does anyone know how to combine several rtf lines into ONE rtf text.

I prefer answers using VBA.

Of course, if anyone knows how to extract notes from MS Project and create a .DOC file preserving formats it's ok as well


This is probably not the right answer but you could do this in VBA :

For each RTF files, open and save to the clipboard as rich text (via API), and paste in word.

It's ugly but it works.


I had a similar task to read RTF from a database and create a report for all records preserving the RTF formatting in a Word document. The code gets the RTF from the DB, writes it to a file with .rtf extension, then inserts the file into a table cell. Not exactly what you are doing I guess, but the report does display all the formatted text from N records.

So the "files" are not really "combined."

The Word table did paste into Excel manually and the formatting was preserved. I don't know the equivalent of InsertFile in Excel.

    RS.Open SQL, con
    Do Until RS.EOF
        Set ts = fso.CreateTextFile("c:\temp\temp.rtf", True)
        ts.Write RS(0)
        ts.Close
        If iRow > 1 Then tbl.Rows.Add
        tbl.Cell(iRow, 1).Range.InsertFile "C:\temp\temp.rtf", , False
        .....
        iRow = iRow + 1
        RS.MoveNext
    Loop

A reference to Microsoft Scripting Runtime is needed and this:

    Dim ts As TextStream
    Dim fso As New FileSystemObject
0

精彩评论

暂无评论...
验证码 换一张
取 消