自动 Outlook 和 Word 创建电子邮件
我正在尝试创建一封将用作 Outlook 邮件正文的 Word 电子邮件。 我一直在查看 Microsoft 此处 的示例代码,但在尝试创建时此代码失败了wordApp.Documents.Add 行的新 Word 文档:
Word.Application wordApp = new Word.Application();
object template = System.Reflection.Missing.Value;
object newTemplate = System.Reflection.Missing.Value;
object documentType = Word.WdNewDocumentType.wdNewEmailMessage;
object visible = false;
Word.Document wordDoc = wordApp.Documents.Add(ref template, ref newTemplate, ref documentType, ref visible);
Outlook.MailItemClass mItem = (Outlook.MailItemClass)doc.MailEnvelope.Item;
我收到“命令失败”的 COM 异常。 我正在使用 Office 2007 并尝试过:
- 引用标准 Office 12 Word 和 Outlook 库
- 安装 Office XP PIA 并引用 Office 12 库
- 安装 Office XP PIA 并引用 Office 2000 库。
- 卸载 Office XP PIA 并引用 Office 2000 / Office 2007 库。
我每次都会遇到同样的错误。 如果我将文档类型从 wdNewEmailMessage 更改为 wdNewBlankDocument 那么它就可以工作。 但我不需要普通的 Word 文档,我想要 EmailDocument - 在转换为 Outlook.MailItemClass 时使用不同类型的文档会引发错误。
理想情况下,我希望该应用程序能够在 Word 2000 到 Word 2007 上运行;-)
I'm trying to create a Word email message that will be used as the body for an Outlook message. I've been looking at sample code from Microsoft here but this code falls over when trying to create the new word document at the wordApp.Documents.Add line:
Word.Application wordApp = new Word.Application();
object template = System.Reflection.Missing.Value;
object newTemplate = System.Reflection.Missing.Value;
object documentType = Word.WdNewDocumentType.wdNewEmailMessage;
object visible = false;
Word.Document wordDoc = wordApp.Documents.Add(ref template, ref newTemplate, ref documentType, ref visible);
Outlook.MailItemClass mItem = (Outlook.MailItemClass)doc.MailEnvelope.Item;
I get a COM Exception of "Command Failed". I'm using Office 2007 and have tried:
- Referencing the standard Office 12 Word and Outlook libraries
- Installing the Office XP PIAs and referencing the Office 12 libraries
- Installing the Office XP PIAs and referencing the Office 2000 libraries.
- Uninstalling the Office XP PIAs and referencing the Office 2000 / Office 2007 libraries.
I get the same error every time. If I change the document type from wdNewEmailMessage to wdNewBlankDocument then it works. But I don't want a normal Word document I want an EmailDocument - using a differnt type of document throws error when casting to the Outlook.MailItemClass.
Ideally I would like the application to work on Word 2000 to Word 2007 ;-)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论