outlook-vba

outlook macro advanced search

心已入冬 提交于 2019-12-25 05:05:28
问题 I would like to create a macro to perform an "Advanced Search" on tasks subject and optionally tasks body. For instance search for "@Cris" I have copied and modified this code from an example for Excel but it doesnt run. Runtime Error. Appreciate any assistance Sub AdvancedSearchComplete() Dim rsts As Outlook.Results Dim i As Integer Dim strF As String Dim strS As String strS = "Tasks" StrName = InputBox("Search String?") strF = InStr(LCase("urn:schemas:tasks:subject"), StrName) Set sch =

Using Microsoft Access, need to pull attachments from Outlook emails of a different account

别说谁变了你拦得住时间么 提交于 2019-12-25 04:46:21
问题 I have working code below to extract attachments from my own Outlook email account, however I need to do it for a different account that is setup as a default reply email box for an automated process. I'm not entirely sure how to tell the code below to check for that mailbox instead of my own. I've tried different variations of setting the Inbox variable, but none of them have worked thus far. This is done within Access 2013. Private Sub GetAttachments() Dim ns As Namespace Dim Inbox As

outlook VBA script run-time error 13 randomly while iterating emails in a public folder

痴心易碎 提交于 2019-12-25 04:42:09
问题 I am receiving a random run-time error 13 (type mismatch) executing the following subroutine. This routine works most of the time. The Folder passed in as an argument is legitimate at the time of the failure. From what I can see in the debugger, the objitem is missing some of the fields during runtime. After it break-points in the debugger, I can immediately single-step (re-executing the offending line) and there is no error. I have attempted using 'on error goto' to sleep then retry various

Missing Outlook MailItem Properties in Application_ItemSend

江枫思渺然 提交于 2019-12-25 04:28:10
问题 I have the code below in which the SenderName MailItem property appears blank. Private Sub Application_ItemSend(ByVal MyItem As Object, Cancel As Boolean) Dim res As Integer ' The "Class" MailItem property is found If MyItem.Class = olMail Then ' This is coming up blank ' The "SenderName" MailItem property is not apparent MsgBox MyItem.SenderName res = MsgBox("Archive outgoing email?", vbQuestion + vbYesNo, "XYZ") If res = vbYes Then Call ProcessIt(MyItem) Else Cancel = True End If End If End

Searching for phone numbers in email subject line

人盡茶涼 提交于 2019-12-25 04:27:18
问题 Starting with the example at http://msdn.microsoft.com/en-us/library/office/aa209973(v=office.11).aspx, I was able to create the following block of code that searches the Outlook inbox for emails where the subject line starts with a specific phone number '555-5555' using "ci_startswith". Public blnSearchComp As Boolean Private Sub Application_AdvancedSearchComplete(ByVal SearchObject As Search) MsgBox "The AdvancedSearchComplete Event fired." blnSearchComp = True End Sub Sub

Searching for phone numbers in email subject line

折月煮酒 提交于 2019-12-25 04:27:11
问题 Starting with the example at http://msdn.microsoft.com/en-us/library/office/aa209973(v=office.11).aspx, I was able to create the following block of code that searches the Outlook inbox for emails where the subject line starts with a specific phone number '555-5555' using "ci_startswith". Public blnSearchComp As Boolean Private Sub Application_AdvancedSearchComplete(ByVal SearchObject As Search) MsgBox "The AdvancedSearchComplete Event fired." blnSearchComp = True End Sub Sub

Copy method in ItemAdd generates Runtime Error

烈酒焚心 提交于 2019-12-25 04:21:55
问题 When I run this code I get the error: Run-Time error '-2147221233 (8004010f)': The attempted operation failed. An object could not be found. Everything is working despite the error. The error disappears if I change the line 'MsgBox "Awesome" to MsgBox "Awesome" A few tests showed that the error does occur if item.Sendername is used with the copy part. If I do just move the mail it works perfectly. If I try to use the code separately it works without errors. Private WithEvents snItems As Items

Always CC when sending “On Behalf Of”

牧云@^-^@ 提交于 2019-12-25 04:04:02
问题 I often send emails on behalf of another user. I'd like to use VBA to automatically CC that user every time I send an email from/on behalf of that user. I'm not familiar with VBA for Outlook but I'm thinking you could write an if statement that says "if sending message from UserX, cc UserX". The code should run automatically any time an email is sent on behalf. 回答1: SentOnBehalfOfName is tricky. It is usually empty until the item has been sent. With this code in ThisOutlookSession you should

Outlook 2010 VBA How to save message including attachment

左心房为你撑大大i 提交于 2019-12-25 02:24:05
问题 Hello am using the following code to save messages to a folder, however if a message has an attachment it does not work. I know if I manually move a message to the hard drive the attachment is still within the *.msg file. I think it is how I am saving the message in this particular section oMail.SaveAs sPath & sName, olMSG How can I alter the following code to do this through VBA. Sub SaveMessageAsMsg() Dim oMail As Outlook.MailItem Dim objItem As Object Dim sPath As String Dim dtDate As Date

Change mail item within the Application_NewMail Event

断了今生、忘了曾经 提交于 2019-12-25 01:53:25
问题 I overwrite the Application_NewMail() function, in order to do something with the incoming mail. If the incoming mail matches given condition, then I want to do olMail.Subject = "Mymark" + olMail.Subject or I do olMail.Categories = "MyMark". But it seems that I do this too late, because the mail is already in inbox and theese changes are not propagated. Private Sub Application_NewMail() Dim olFld As Outlook.MAPIFolder Set olFld = Outlook.Session.GetDefaultFolder(olFolderInbox) olFld.Items