我在Excel中有一个名字和姓氏的列表,我想利用该列表在Outlook中使用visual basic查找电子邮件地址.
我正在使用以下VB代码:
Private Sub GetAddresses()
Dim o, AddressList, AddressEntry
Dim c As Range, r As Range, AddressName As String
Set o = CreateObject("Outlook.Application")
Set AddressList = o.Session.AddressLists("Global Address List")
Set r = Range("a1:a3")
For Each c In r
AddressName = Trim(c.Value) & ", " & Trim(c.Offset(0, 1).Value)
For Each AddressEntry In AddressList.AddressEntries
If AddressEntry.Name = AddressName Then
c.Offset(0, 2).Value = AddressEntry.Address
Exit For
End If
Next AddressEntry
Next c
End Sub
Run Code Online (Sandbox Code Playgroud)
代码似乎工作正常,直到实际检索电子邮件地址.在匹配名称后,返回以下内容而不是地址.有没有人知道我做错了什么.
/O=Compnay/OU=Company/cn=Recipients/cn=shs
Run Code Online (Sandbox Code Playgroud)
在此先感谢您的帮助.
Outlook 2007中是否有办法在电子邮件对象上设置后续标志?看起来它在Outlook 2003中支持.FlagStatus属性,但我在2007年找不到它.
我需要知道如何一次移动对话中的所有消息.
我的宏目前正在阅读
Sub Archive()
Set ArchiveFolder = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Parent.Folders("Archive")
For Each Msg In ActiveExplorer.Selection
Msg.UnRead = False
Msg.Move ArchiveFolder
Next Msg
End Sub
Run Code Online (Sandbox Code Playgroud)
但这只会移动最新消息......并且只有当对话完全崩溃时!在扩展对话时我无法存档.
我有一个电子邮件模板,其中包含html格式和占位符以换出实际值.
在Excel中,我通过Outlook CreateItemFromTemplate方法加载电子邮件.如果此时我保存电子邮件格式保留.
如果我在身体上执行替换,大多数格式都会被删除:
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItemFromTemplate("template.oft") ' <- has lots of html formatting
With OutMail
.Body = Replace(.Body, "#recipient#", "Some other value") ' <- Strips out most formatting!!
.Save ' <- this works fine without the line above.
End With
Run Code Online (Sandbox Code Playgroud) 我有以下VBA代码,用于在收到特定主题时发送自动电子邮件.
Private WithEvents Items As Outlook.Items
Private Sub Application_Startup()
Dim objNS As Outlook.NameSpace
Set objNS = GetNamespace("MAPI")
Set Items = objNS.GetDefaultFolder(olFolderInbox).Items
End Sub
Private Sub Items_ItemAdd(ByVal item As Object)
If item.Class = olMail Then
If Left$(item.Subject, 29) = "Hazard Identification Report" Then
Dim Msg As Outlook.MailItem
Dim NewForward As Outlook.MailItem
Dim myFolder As Outlook.MAPIFolder
Dim olApp As Outlook.Application
Dim olNS As Outlook.NameSpace
Set Msg = item
Set NewForward = Msg.Forward
Set olApp = Outlook.Application
Set olNS = olApp.GetNamespace("MAPI")
strSender = …Run Code Online (Sandbox Code Playgroud) 我有以下代码部分,它是我正在开发的自动回复系统的一部分.据我所知,它应该使用换行符格式化电子邮件的正文,但是,如附带的屏幕截图所示,它不会.有人会指出我出错的地方吗?
With NewForward
.Subject = "'TEST' Hazard report reciept number: HAZ" & IDnumber
.To = strSender
.BCC = "xxxxxxxxxxxx"
.HTMLBody = "Please accept this email as confirmation that xxxx has received your road defect notification. xxxxx will investigate and action your notification according to priority and to ensure public safety. For further information, please phone xxxxx on 4221 6111 and quote reference number " & vbCrLf & IDnumber & vbCrLf & "Your original report can be seen below:" …Run Code Online (Sandbox Code Playgroud) 我尝试创建一个宏来设置Outlook电子邮件中的选择语言.
我在VBA脚本方面经验不足.
我将我在Word中录制的宏复制到我的Outlook宏窗口(或项目,或模块,我不知道它是如何命名的)
Sub SelectionEnglish()
Selection.LanguageID = wdEnglishUS
Selection.NoProofing = False
Application.CheckLanguage = True
End Sub
Run Code Online (Sandbox Code Playgroud)
这不起作用,因为Selection对象不可用.但我看到了另一个问题(我再也找不到了)宏观作者在outlook宏中使用word-editor的方法.
每当发送电子邮件时,我都希望将该电子邮件的副本与所有附件一起保存在本地文件夹中.
我不认为这可以在Outlook中使用自定义规则,但也许可以使用VBA脚本完成?
我使用Outlook和MS Exchange.
我正在尝试通过VBA在Outlook中打开文件对话框.(Outlook 2010)
使用以下代码我得到一个错误:
运行时错误438.对象不支持此属性或方法
Private Sub btn_openPST_Click()
Dim oFileDialog As FileDialog
Set oFileDialog = myAppl.FileDialog(msoFileDialogFilePicker)
With oFileDialog
.Title = "Select your PST File"
.ButtonName = "Ok"
.Show
End With
End Sub
Run Code Online (Sandbox Code Playgroud)
myAppl是一个Outlook.Application对象:
Dim myAppl As Outlook.Application
Set myAppl = CreateObject("Outlook.Application")
Run Code Online (Sandbox Code Playgroud) 如果有超过15分钟的未读电子邮件,我正在尝试向自己发送电子邮件。
当我从Outlook内部手动运行时,该代码发送了邮件,但我收到了
运行时错误'-2147221238'(8004010a)
由于上述错误,我无法使其从规则中运行或与任务计划单独运行。
Sub checkForUnreadMails()
Dim objFolder, objNamespace
'get running outlook application or open outlook
Set objOutlook = GetObject(, "Outlook.Application")
If objOutlook Is Nothing Then
Set objOutlook = CreateObject("Outlook.Application")
End If
Set objNamespace = objOutlook.GetNamespace("MAPI")
Set objMsg = Application.CreateItem(olMailItem)
strFilter = "[received] <= '" & Format(DateAdd("n", -15, Now()), "ddddd h:nn AMPM") & "'"
Debug.Print strFilter
Set inboxItems = objNamespace.GetDefaultFolder(olFolderInbox).Items.Restrict(strFilter)
strFilter = "[Unread] = True"
Set unreadItems = inboxItems.Restrict(strFilter)
For Each itm In unreadItems
With objMsg
.To = "email@email.com"
.Subject …Run Code Online (Sandbox Code Playgroud) outlook-vba ×10
vba ×10
outlook ×6
email ×1
excel ×1
excel-vba ×1
outlook-2007 ×1
outlook-2010 ×1