Quantcast
Channel: All OutlookCode.com content
Viewing all 871 articles
Browse latest View live

Rule to call code isn't working

$
0
0
HI, I have the code below called by a rule, which fires if a message with a certain subject comes in. The rule runs but the code doesn't fire. I've set the security settings to low. I have other code running on the same machine - even with another rule - but this one won't work. Any suggestions would be gratefully received. Thanks Robert ----------- Public Sub DetachNN4B(MyMail As MailItem) Dim strID As String Dim objMail As Outlook.MailItem Dim myAttachments As Outlook.Attachments Dim AttName(4) As String Dim MailTo As String Dim OlkMail As MailItem Dim x As Long Set OlkMail = Application.CreateItem(olMailItem) MailTo = "me@myaddress.com" On Error GoTo Err strID = MyMail.EntryID Set objMail = Application.Session.GetItemFromID(strID) Set myAttachments = objMail.Attachments For x = 1 To 10000000 Next x For x = 1 To myAttachments.Count AttName(x) = Right(myAttachments.Item(x).FileName, 3) Debug.Print " AttName(" & x & "): " & AttName(x) If AttName(x) = "HTM" Then myAttachments.Item(x).SaveAsFile "Z:\" & myAttachments.Item(x).FileName End If Next With OlkMail .To = "me@myaddress.com" .Subject = "Delivery" .Body = "The attachment has been delivered." .Send End With GoTo EndofFile Err: On Error GoTo 0 With OlkMail .To = "me@myaddress.com" .Subject = "Non-Delivery" .Body = "The attachment has NOT been delivered." .Send End With EndofFile: Set objMail = Nothing Set OlkMail = Nothing End Sub

saving a messages as .txt files on receipt

$
0
0
Hi All, I need to save all the emails received in a mailbox as text files. Many emails are received at once. The mailbox is attached to an AD account which is permanently logged in. I've used an 'after message arrives' rule to run a VBA script that saves off all the messages in the inbox and moves them to an outlook folder as follows; Public Sub MyRuleScript() Dim myOlApp As New Outlook.Application Dim myNameSpace As Outlook.NameSpace Dim myInbox As Outlook.MAPIFolder Dim myDestFolder As Outlook.MAPIFolder Dim myItems As Outlook.Items Set myNameSpace = myOlApp.GetNamespace("MAPI") Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox) Set folderSavedCerts = myInbox.Folders("SavedCerts") Set folderNotCerts = myInbox.Folders("NotCerts") 'Use subject to determine whether this is a certificate notification, if so then 'move the email to Inbox.SavedCerts and save the cert to \\infpv-db02\CertificateData\ToProcess 'if not then move the email to Inbox.NotCerts Dim i As Integer Dim MyMailItem As MailItem For Each MyMailItem In myInbox.Items If InStr(MyMailItem.Subject, "Notification of RENEWABLE LECs Issue Approval") > 0 Or InStr(MyMailItem.Subject, "Notification of ROCs Issue Approval") > 0 Then Dim filename As String filename = MyMailItem.Subject + CStr(DateTime.Now) + "_" + CStr(i) i = i + 1 MyMailItem.SaveAs "\\infpv-db02\CertificateData\ToProcess\" + Replace(Replace(filename, ":", ""), "/", "") + ".txt", olTXT MyMailItem.Move (folderSavedCerts) Else MyMailItem.Move (folderNotCerts) End If Next This script seems to miss the odd email which is causing havoc with a downstream process that extracts data from the text files. I'm not sure if my approach is best, I've tried handling the NewMsg event and have had similar problems. I'm not sure this is the best approach. Ideally I would like to configure the exchange server to save off the messages so Oultlook doesn't nee to be left running. Thanks in advance Alex

Checking email size when sent via context menu

$
0
0
Hi I have been using a basic script (modified from one I found on the web) to check for the size of email attachments and alert me if the email is over 100kb. This works fine for emails generated within Outlook, but if I send attachments using the Windows Explorer context menu "send to", the script does not seem to be activated. The script I am using (pasted into ThisOutlookSession) is: Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean) If TypeOf Item Is Outlook.MailItem Then Cancel = (ConfirmBigAttachments(Item)) End If End Sub Private Function ConfirmBigAttachments(oMail As Outlook.MailItem) As Boolean Dim lSize As Long Dim XX As Integer Const MAX_SIZE As Long = 102400 ' Byte Dim bSend As Boolean lSize = 0 bSend = False If oMail.Attachments.Count Then oMail.Save lSize = lSize + oMail.Size End If If lSize > MAX_SIZE Then XX = lSize / 1024 bSend = (MsgBox("Attachment size (choose No to change sending account): " & XX & " KB. Send it?", vbYesNo) = vbNo) End If ConfirmBigAttachments = bSend End Function Any suggestions how I can get this to work Thanks Trevor

Make BCC Field in mail inspector visible programmatically

$
0
0
Hello all, i'm just facing the problem that i want to make the bcc field in a mail inspector visible because this field is not shown by default. this should be triggered in an event method. i searched a lot and i just found ways to add custom things to the microsoft ribon but not to make already existing outlook elements like this bcc field visible. Some help here would be really really nice. i found things like this that don't work: this.Application.ActiveInspector().CommandBars.FindControl(Tag: "BCC Field).Visible = true; is that totally wrong or am i on a good way? Thanks for any help Tobi

To address not working in Exchange

$
0
0
I used to have pop3 email account in Outlook and used the following code to obtain the adress an email was sent to. I have one email account and many aliases that points in to this account. objMsg.Recipients.Item(n).Address Now I have changed to Exchange and this is not working anymore. I am just getting the Account name. Is there a way to obtain the email adress an email is sent to.

signature via vba

$
0
0
i found this code that convert email to html on reply, but it will not insert my signature. any ideas why? Option Explicit Private WithEvents oExpl As Explorer Private WithEvents oItem As MailItem Private bDiscardEvents As Boolean Private olFormat As OlBodyFormat Private Sub Application_Startup() Set oExpl = Application.ActiveExplorer bDiscardEvents = False 'olFormat = olFormatPlain '(*1) - uz.ywaj zawsze formatu "zwyk?y tekst" olFormat = olFormatHTML '(*2) - uz.ywaj zawsze formatu HTML End Sub Private Sub oExpl_SelectionChange() On Error Resume Next Set oItem = oExpl.Selection.Item(1) End Sub ' (*3) Uz.ytkownik wybra? polecenie "Odpowiedz" Private Sub oItem_Reply(ByVal Response As Object, Cancel As Boolean) If bDiscardEvents Or oItem.BodyFormat = olFormat Then Exit Sub End If '(*4) Anuluj domys'lna; akcje; Cancel = True bDiscardEvents = True ' (*5) Utwo'rz odpowiedz' na wiadomos'c' w formacie tekstowym Dim oResponse As MailItem Set oResponse = oItem.Reply oResponse.Display oResponse.BodyFormat = olFormat bDiscardEvents = False End Sub ' (*6) Uz.ytkownik wybra? polecenie "Odpowiedz wszystkim" Private Sub oItem_ReplyAll(ByVal Response As Object, Cancel As Boolean) If bDiscardEvents Or oItem.BodyFormat = olFormat Then Exit Sub End If Cancel = True bDiscardEvents = True Dim oResponse As MailItem Set oResponse = oItem.ReplyAll oResponse.BodyFormat = olFormat oResponse.Display bDiscardEvents = False End Sub ' (*7) Uz.ytkownik wybra? polecenie "Przes'lij dalej" Private Sub oItem_Forward(ByVal Forward As Object, Cancel As Boolean) If bDiscardEvents Or oItem.BodyFormat = olFormat Then Exit Sub End If Cancel = True bDiscardEvents = True Dim oResponse As MailItem Set oResponse = oItem.Forward oResponse.BodyFormat = olFormat oResponse.Display bDiscardEvents = False End Sub

Help with Regular Expression pattern

$
0
0
Hi, I'm looking for some help with Regular Expressions I want to add a registration nummer to a email witch I have in a string I want tot test if the registration number is in the correct format with a Regular Expressions It can only be true if the string contains: 1234567 (7 digits 0-9) or CC + 000000 + 7303964 Example CC0000007303964 or 7303964 is correct (true) This is the Pattern I have now: "(^CC)+(\d{13})|\d{7}" And the code: Public Function IsTicketNr(myText) As Boolean Dim regEx Set regEx = New RegExp 'Regular expression object regEx.Pattern = "(^CC)+(\d{13})|\d{7}" ' Set pattern. IsTicketNr = regEx.test(myText) ' Test for match End Function The code is working, but I think the Pattern is wrong! can anybody help? THX for reading my question

Searching a second email account folders

$
0
0
Hi, I'm new to coding applications in Outlook..Doing some work on a mates website. We have set up Outlook 2007 to receive is default email account and also as an email client for his website email address. I need to be able to access the folders in the 2nd email account say admin@website.com. I shortened the name in the folder tree to admin. I cannot work out how to access this folder or any folders under this. I purchased the Outlook Tutorial e-Book which is great has help me under the basic structure. And I worked out have to access all the main folders via the inbox. So tree looks something like this... Personnel Folders Inbox Folder1 Folder2 Sent etc admin (2nd account- Website email account imap) Inbox Sales How do I access the Sales folder in the admin account? Dim mapiNameSpace As NameSpace Dim admin As MAPIFolder Dim mailItems As Items Dim NumItems As Integer Set mapiNameSpace = Application.GetNamespace("MAPI") Set admin = mapiNameSpace.GetDefaultFolder(olFolderInbox) Set mailItems = admin.Folders("admin").Folders("Sales").Items Any ideas would be appreciated!! Thanks coda

How to copy HTML mailItem.Body with line breaks to a website Textarea?

$
0
0
I have a problem with this code, which copies the body in "clear text" to a text area field on a website.. The HTML E-mail looks like this Try this out too. Me team name phone email when I populate hte text area with objitem.body it looks like this (note the extra line breaks): Try this out too. Me team name phone HYPERLINK "mailto:email"email

saving OLE attachment from mail to a folder on c-drive

$
0
0
Hello, I can save attachments with the SaveAsFile method, but for OLE attachments it does not work. In the mail directly I can copy the OLE-Object, paste it into word, then save it. How can I do such a thing in vba? Or saving the OLE-Object somehow on my c-drive? Regards Frank

Auto Save Attachments to harddisk from PublicFolder

$
0
0
Hi, hope you can help me. I'm trying to change some code to auto save attachments from incoming emails from a public folder. The code works fine on my inbox, but I can't seem to get it work on the public folder. I used a rule for my inbox and point to my script, but don't know how to do that for my public folder? I placed my code in thisoutlooksession and in a seprate module. I'm a noob for scripting so please forgive me my ingnorance. Here is the code I use: Sub SaveAttachmentsToFolder(Item As Outlook.MailItem) Dim ns As NameSpace Dim Inbox As MAPIFolder Dim SubFolder As MAPIFolder Dim Item As Object Dim Atmt As Attachment Dim FileName As String Dim MyDocPath As String Dim I As Integer Dim wsh As Object Dim fs As Object On Error GoTo ThisMacro_err Set ns = GetNamespace("MAPI") Set Inbox = ns.GetDefaultFolder(olPublicFoldersAllPublicFolders) Set SubFolder = Inbox.Folders("Fax") I = 0 ' Check subfolder for messages and exit of none found If SubFolder.Items.Count = 0 Then MsgBox "There are no messages in this folder : " & OutlookFolderInInbox, _ vbInformation, "Nothing Found" Set SubFolder = Nothing Set Inbox = Nothing Set ns = Nothing Exit Sub End If 'Create DestFolder if DestFolder = "" If DestFolder = "" Then Set wsh = CreateObject("WScript.Shell") Set fs = CreateObject("Scripting.FileSystemObject") MyDocPath = wsh.SpecialFolders.Item("mydocuments") DestFolder = "G:\tmp\fax" If Not fs.FolderExists(DestFolder) Then fs.CreateFolder DestFolder End If End If If Right(DestFolder, 1) <> "\" Then DestFolder = DestFolder & "\" End If ' Check each message for attachments and extensions For Each Item In SubFolder.Items For Each Atmt In Item.Attachments If LCase(Right(Atmt.FileName, Len(ExtString))) = LCase(ExtString) Then FileName = DestFolder & Atmt.FileName Atmt.SaveAsFile FileName I = I + 1 End If Next Atmt Next Item ' Show this message when Finished If I > 0 Then MsgBox "You can find the files here : " _ & DestFolder, vbInformation, "Finished!" Else MsgBox "No attached files in your mail.", vbInformation, "Finished!" End If ' Clear memory ThisMacro_exit: Set SubFolder = Nothing Set Inbox = Nothing Set ns = Nothing Set fs = Nothing Set wsh = Nothing Exit Sub ' Error information ThisMacro_err: MsgBox "An unexpected error has occurred." _ & vbCrLf & "Please note and report the following information." _ & vbCrLf & "Macro Name: SaveEmailAttachmentsToFolder" _ & vbCrLf & "Error Number: " & Err.Number _ & vbCrLf & "Error Description: " & Err.Description _ , vbCritical, "Error!" Resume ThisMacro_exit End Sub

Outlook program to move Attachments to SubFolder - Getting Object not found error

$
0
0
I have written this small program in VS2010 to run on Outlook 2007. It works for a standard read through of the Inbox, but I cannot get it to correctly point to other Folders, I am getting a "COMException was unhandled by user code" error that says "The operation failed. An object could not be found." ... My Outlook structure has "Outlook (Gary)" at the top & INBOX & Kickabout are both first level Folders with Location Properties of "\\Outlook (Gary)", whereas the Attachments folder is within Kickabout and it has a Location Property of "\\Outlook (Gary)\Kickabout". So what can't be found ?!? Imports Microsoft.Office.Interop Public Class ThisAddIn Private Sub ThisAddIn_Startup() Handles Me.Startup End Sub Private Sub ThisAddIn_Shutdown() Handles Me.Shutdown End Sub Private Sub Application_Startup() Handles Application.Startup Dim MyApp As Outlook.Application = New Outlook.Application Dim MyNS As Outlook.NameSpace = MyApp.GetNamespace("MAPI") Dim MyInbox As Outlook.MAPIFolder = MyNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox) Dim MyEmails As Integer = MyInbox.Items.Count Dim MyEMail As Outlook.MailItem Dim MyCount As Integer Dim MySubFolder As Outlook.MAPIFolder = MyNS.Folders("Kickabout") **<<< Error occurs here** For MyCount = MyEmails To 1 Step -1 MyEMail = MyInbox.Items(MyCount) If MyEMail.SenderEmailAddress = "MrX@abc.com" Then If MyEMail.Attachments.Count > 0 Then MySubFolder = MyNS.Folders("Kickabout\Attachments") End If MyEMail.Move(MySubFolder) End If Next End Sub End Class BTW ... I have tried various code for the SubFolder variable and continually get the same error, my last attempt was as follows : Dim MySubFolder As Outlook.MAPIFolder = MyNS.Folders.Item("Kickabout")

Warning before sending email to EXTERNAL recipients

$
0
0
Hi all, I have this scrip running on users outlook right now -see below (Thanks to whoever posting this online :-)The problem is that I could not figure out how to generate send warning ONLY when email is send to EXTERNAl recipients. Is there a way that i can compare to GAL or domain name and only generate send warning if To, CC, or BCC contain external email address? Really appreciated for any help. Private Sub Application_ItemSend _ (ByVal Item As Object, Cancel As Boolean) Dim strMsg As String strMsg = "To recipients = " & Item.To & vbCrLf & vbCrLf & _ "Cc recipients = " & Item.CC & vbCrLf & vbCrLf & _ "Bcc recipients = " & Item.BCC & vbCrLf & vbCrLf & _ "Are you sure you want to send this message?" If MsgBox(strMsg, vbYesNo + vbQuestion _ , "SEND CONFIRMATION") = vbNo Then Cancel = True End If End Sub

Filter email based on phrase in subject or body

$
0
0
Hi All, I was having a play around with creating VBA based filters in outlook, and would like to try and streamline the process and make it more efficient. Anyway what I was essentially doing was creating an email ticket / tracking system, whereby when an email was received, it would look for a code between two brackets [ & ], and see with this code if a folder exists with that code, and if not then create it, then copy the email into the subfolder (of another folder), otherwise it would not bother creating the folder, and would email it in. My question is, how can I detect the string when it varies (and I don't want to use the [ & ]), the codes are almost always the same format (or variants of). For example CV120112 CV120112A (or a, b, c, d and so on) CN120894 CN120894A (or a, b, c, d and so on) CVQ120987 CNQ125498 These are almost always in the format of Prefix YY MM ID (no Spaces), where prefix is CN, CV, CVQ, CNQ How can I extract this string into a variable, from which i can then use to determine what to actually do with the email. Thanks for any help you can provide :) (p.s. I would be working in VBA)

Help with VBA code for run a script

$
0
0
I have a folder structure as below: Inbox ..a ....b ....c ....d ....e I want to create a VBA "run a script" code that will move all the incoming mails to each of these folder based on "to" address. so if mail is sent to a.b@domain.com move it to Inbox.a.b folder so if mail is sent to a.c@domain.com move it to Inbox.a.c folder Can we create a rule using wildcards which moves the mails so if mail is sent to a.*@domain.com move it to Inbox.a.* folders?

"MAPI Error: Unknown Error" displayed when OUTLOOK custom form is published

$
0
0
Hi, We have a custom Outlook Appointment form (.oft file) created, with only textboxes, labels and checkboxes. Recently, we redesigned the custom form to include the control, as in the screen shot, to the custom form. Post the design change, we are not able to publish the form, both to the Organization Forms Library and Personal Forms library of the Exchange Server and of the user. We are getting a "MAPI Error: Unknown Error", when trying to publish. But we are able to publish the same custom form, without any issue in another similar environment (WINDOWS, EXCHANGE SERVER and OUTLOOK). Can somebody, help on why this is happening and the solution for the same.

Positioning VBA forms

$
0
0
Hello, I have written many VBA macros in Excel but I'm working on my first instance of an Outlook macro. This problem seems very simple but I can't seem to fix it. I use a dual monitor setup and have Outlook and Excel displayed on the secondary monitor. After I "upgraded" to Windows 7, I found that all my Excel macro userforms opened on my primary monitor, even if the window StartupPosition was set to CenterOwner. I solved this problem by writing a sub that executes on the userform Initialize event that positions the form relative to the Application.Left and Application.Top properties. My new Outlook macro monitors incoming emails and compares the sender's address to my Contacts list and to a separate ignore list. If it's not found in either place, a window is displayed that allows me to fill in some extra data and add it to my contacts or to the ignore list. Everything seems to be working so far except, like in Excel, the userform opens on the opposite monitor. I tried to transfer my Excel macro but the Outlook application module doesn't seem to support the left and top properties. Can anyone help me? I just want my userform to display over the application. By the way, I'm new here. Great site!

Converting a label to a Hyperlink

$
0
0
Hi, I created a form in Outlook 2007 which has labels that display URL names depending on user input.... I want to be able to convert those labels(captions) to a Hyperlink so that when I click the label it will navigate to the url... I'm using Chrome as my browser... I can't use Linklabel as its not available in my version of outlook Code thus far.. Private Sub Label21_Click() Dim label21URL As String label21URL = Label21.Caption Shell (ChromePath & " -url Label21.Caption") End Sub Problem is Chrome navigates to "Label21.Caption" not that actual URL name that is in Label21 For example... if Label21 value is www.google.com.au it doesn't navigate to this but tries to navigate to the name Label21.Caption... Do I have to concert the Labe121.caption to another type for the Shell(Chrome etc) to be see the string value in the label21 ? Help would be apprecaited.. Regards Bruce

Issue with a custom form

$
0
0
Hello, I've created a form that my organization is using for 2 years. Since two days, some members of my organization have a message when they try to open the form from the Organizational Forms Library. This message says that they don't have the rights to perform an action, and the form won't open. When I use these accounts on another computer, with outlook, they have no issue using this form. On the computer where they have this error message, I've tried to : - clear the outlook cache - repair the installation of Office suite - uninstall and reinstall the form in the Organizational Forms Library - remove the frmcache.dat file - remove files in %AppData%\Local\Microsoft\Outlook and %AppData%\Roaming\Microsoft\Outlook folders None of these actions has fixed the issue. We are using outlook 2010 and win 7 on the computer where the issue happened. Can you help me to fix this issue ? Thank you.

Need Help with VBA Code to Download Full Items/Including Attachments Upon E-mail Arriving

$
0
0
Hello, I wanted to write some VBA code that automatically to "Download the complete item including attachments" whenever an e-mail arrives in Outlook. I currently use outlook 2007 with IMAP settings. I'm also a beginner at Outlook VBA code so would appreciate any help you can offer.
Viewing all 871 articles
Browse latest View live