我拥有的是一段类似的代码&我使用outlook编辑器(足够努力),我试图让它现在使用Word作为outlook编辑器。 (用户习惯于发送邮件)我试过:要将代码直接移到本文档下的单词中,它什么也没做。按照我看到的代码:创建一个objword objdoc,然后将它与outlook类的交易配对,没有运气。以下是代码示例:
Sub SetCategory()
Dim olMessage As Outlook.MailItem
Set olMessage = Application.ActiveInspector.CurrentItem
If olMessage.SenderName = donations Then
olMessage.Categories = "donations"
ElseIf olMessage.SenderName = "Donations" Then
olMessage.Categories = "donations"
End If
With olMessage
.Send
End With
End Sub
答案 0 :(得分:1)
使用" word mail"你没有使用Outlook。这描述了如何从Word调用Outlook。 Outlook打开后,您可以使用Outlook VBA。
http://www.howto-outlook.com/howto/senddocasmail.htm
未经测试,您将不得不删除不需要的部分。
Sub SendDocAsMail()
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem
On Error Resume Next
'Start Outlook if it isn't running
Set oOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
Set oOutlookApp = CreateObject("Outlook.Application")
End If
On Error GoTo 0 ' <=== Important to see errors now if there are any
'Create a new message
Set oItem = oOutlookApp.CreateItem(olMailItem)
' --------------------------
'Set oItem = oOutlookApp.ActiveInspector.CurrentItem
If oItem.SenderName = donations Then
oItem.Categories = "donations"
ElseIf oItem.SenderName = "Donations" Then
oItem.Categories = "donations"
End If
' --------------------------
'Allow the user to write a short intro and put it at the top of the body
Dim msgIntro As String
msgIntro = InputBox("Write a short intro to put above your default " & _
"signature and current document." & vbCrLf & vbCrLf & _
"Press Cancel to create the mail without intro and " & _
"signature.", "Intro")
'Copy the open document
Selection.WholeStory
Selection.Copy
Selection.End = True
'Set the WordEditor
Dim objInsp As Outlook.Inspector
Dim wdEditor As Word.Document
Set objInsp = oItem.GetInspector
Set wdEditor = objInsp.WordEditor
'Write the intro if specified
Dim i As Integer
If msgIntro = IsNothing Then
i = 1
'Comment the next line to leave your default signature below the document
wdEditor.Content.Delete
Else
'Write the intro above the signature
wdEditor.Characters(1).InsertBefore (msgIntro)
i = wdEditor.Characters.Count
wdEditor.Characters(i).InlineShapes.AddHorizontalLineStandard
wdEditor.Characters(i + 1).InsertParagraph
i = i + 2
End If
'Place the current document under the intro and signature
wdEditor.Characters(i).PasteAndFormat (wdFormatOriginalFormatting)
'Display the message
oItem.Display
'Clean up
Set oItem = Nothing
Set oOutlookApp = Nothing
Set objInsp = Nothing
Set wdEditor = Nothing
End Sub
编辑:添加,基于评论。这是初学者绊倒的一步。
&#34;由于此宏还使用Outlook功能来创建邮件,因此我们必须添加对项目的引用。为此,请选择工具 - &gt;引用...并选择Microsoft Outlook 12.0对象库(或使用Outlook 2010时为14.0)。在此之后按OK。&#34;
答案 1 :(得分:0)
默认情况下,最新的Outlook版本使用Word作为电子邮件编辑器。无需查看编辑器类型。 Inspector类的WordEditor属性返回正在显示的消息的Microsoft Word文档对象模型。您可以在Chapter 17: Working with Item Bodies。
中详细了解相关内容另外,您可能会发现How to automate Outlook and Word by using Visual C# .NET to create a pre-populated e-mail message that can be edited文章有用。