使用 VBA 将多个 RTF 文本合并为一个 RTF 文件
我正在使用 VBA 从 MS Project 中提取“任务注释”,并希望创建一个 MS Word .DOC 文件并将这些文本复制到 EXCEL 中。
如果您使用任务对象的 Notes 属性,您只会获得 255 个字符,并且格式不会保留。 为了保持格式,您可以将 .MPP 文件转换为 .MPD 并提取注释。这些注释已使用 rtf 存储(请参阅 PJDB.HTM 查找“sub getRtf”)。 这样我就可以提取所有笔记并将它们写入 .rtf 文件中。 如果我使用 MS Word 打开该文件(包含多个注释[我已验证]),我只会看到第一个注释(并且格式正确)。 我从其他网站收集的信息了解到,一个文件中仅会处理一个 rtf 文本,并且加入多个 rtf 文本并非易事。
所以我的问题是: 有谁知道如何将多行 rtf 行组合成一个 rtf 文本。
我更喜欢使用 VBA 的答案。
当然,如果有人知道如何从 MS Project 中提取注释并创建保留格式的 .DOC 文件,那也可以
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 retained.
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这可能不是正确的答案,但您可以在 VBA 中执行此操作:
对于每个 RTF 文件,打开并以富文本形式保存到剪贴板(通过 API),然后粘贴到 word 中。
它很丑,但很有效。
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.
我有一个类似的任务,从数据库读取 RTF,并为在 Word 文档中保留 RTF 格式的所有记录创建报告。该代码从数据库获取 RTF,将其写入扩展名为 .rtf 的文件,然后将该文件插入到表单元格中。我猜这不完全是你在做什么,但报告确实显示了 N 条记录中的所有格式化文本。
所以“文件”并不是真正的“组合”。
Word 表格确实手动粘贴到 Excel 中,并且格式被保留。我不知道 Excel 中的 InsertFile 相当于什么。
需要对 Microsoft Scripting Runtime 的引用,如下:
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.
A reference to Microsoft Scripting Runtime is needed and this: