![]() |
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Search this Thread | Display Modes |
#1
|
|||
|
|||
![]()
I am trying to make a VB macro to run Outlook, process every email that comes
to the inbox from a machine that sends an identical email subject with a small amount of descriptive text in the body and a numerical .csv data file attachment. It reads a unique time, date and type from the body then using them, saves the body and attachment with a unique filename as a .txt and a ..csv file respectively. Two problems 1) with the code: Set myNameSpace = Application.GetNamespace("MAPI") Set myFolder = myNameSpace.GetDefaultFolder(olFolderInbox) myFolder.Display it opens a new instance of the inbox every time it executes. How do I prevent that? It displays a security error when it tries to save the data. How do I suppress that error? |
Ads |
#2
|
|||
|
|||
![]()
it opens a new instance of the inbox every time it executes. How do I
prevent that? Don't call the Display method. There should be no reason to do so for your scenario. It displays a security error when it tries to save the data. How do I suppress that error? Please show the relevant code and give your Outlook version. If you are using Outlook 2003 and derive the object from the intrinsic Application object in Outlook VBA, no security prompt should occur. -- Sue Mosher, Outlook MVP Author of Microsoft Outlook 2007 Programming: Jumpstart for Power Users and Administrators http://www.outlookcode.com/article.aspx?id=54 "Perge" wrote in message ... I am trying to make a VB macro to run Outlook, process every email that comes to the inbox from a machine that sends an identical email subject with a small amount of descriptive text in the body and a numerical .csv data file attachment. It reads a unique time, date and type from the body then using them, saves the body and attachment with a unique filename as a .txt and a .csv file respectively. Two problems 1) with the code: Set myNameSpace = Application.GetNamespace("MAPI") Set myFolder = myNameSpace.GetDefaultFolder(olFolderInbox) myFolder.Display it opens a new instance of the inbox every time it executes. How do I prevent that? It displays a security error when it tries to save the data. How do I suppress that error? |
#3
|
|||
|
|||
![]()
Sue,
Here is the whole sub. It is being developed in Outlook 2002. When it gets to the line to save the body it displays a warning. Sub SaveBodyandAttchment() 'To do ' when email received, run this process 'Outlook objects Dim myNameSpace As Outlook.NameSpace Dim myFolder As Outlook.MAPIFolder Dim myItem As Outlook.MailItem Dim myBody As String Dim Rdate As String Dim CType As String Dim ETD As String Dim L As Long Dim SavePath As String 'Open Outlook if not already Set myOlApp = Application 'CreateObject("Outlook.Application") 'set path to save body.txt and data.csv files SavePath = "C:\Terroir\SmartRoast data\" 'Display the inbox (if not already) Set myNameSpace = Application.GetNamespace("MAPI") Set myFolder = myNameSpace.GetDefaultFolder(olFolderInbox) 'myFolder.Display 'diabled to prevent multiple instances 'Select first email and open ' if no items then exit sub If myFolder.Items.Count 0 Then Set myItem = myFolder.Items(1) myItem.Display Else Exit Sub End If 'Get the email body text, find type ' key off the word Bean myBody = myItem.Body L = InStr(myBody, "Bean") 'go back 33 chars to find type number L = L - 33 'MsgBox L 'for debugging 'get type number CType = Mid(myBody, L, 3) 'MsgBox CType 'for debugging 'go back another 31 chars to get date L = L - 31 'and then get the roast time Rdate = Mid(myBody, L, 17) 'MsgBox RDate 'for debugging 'remove special chars in date time string ETD = "" ETD = Replace(Rdate, "/", "") ETD = Replace(ETD, ":", "") ETD = Replace(ETD, " ", "") ETD = Left(ETD, 10) 'MsgBox ETD 'for debugging 'save email body with unique filename as text myItem.SaveAs SavePath & CType & "_" & ETD & ".txt", olTXT 'Save the attachment with unique filename as csv Set myItem = Application.ActiveInspector.CurrentItem Set myAttachments = myItem.Attachments myAttachments.Item(1).SaveAsFile SavePath & CType & "_" & ETD & ".csv" 'Delete the email to avoid duplication myItem.Close (1) 'enabled for debugging 'myItem.Delete 'disbled for debugging Set myNameSpace = Nothing Set myFolder = Nothing Set myItem = Nothing End Sub Also I would like to have Outlook display the inbox not the Today window when it starts up or when this sub runs. Commenting out the myFolder.Display statement prevents this from ever happening. |
#4
|
|||
|
|||
![]() OK, I figured out how to have Outlook open displaying the inbox and I have changed the program so it does not open the individual emails and it loops through the inbox to save them all. Now if if didn't present this error it would be working (except it needs to run on the email received event). I don't know how to attach the .bmp file so I will retype the error message: " A program is trying to access data from Outlook that may include address book information. Do you want to allow this? If this is unexpected, it may be a virus and you should choose"No"." |
#5
|
|||
|
|||
![]()
It's a warning, not an error. See http://www.outlookcode.com/article.aspx?ID=52 for your options with regard to the "object model guard" security in Outlook 2000 SP2 and later versions.
-- Sue Mosher, Outlook MVP Author of Microsoft Outlook 2007 Programming: Jumpstart for Power Users and Administrators http://www.outlookcode.com/article.aspx?id=54 "Perge" wrote in message ... OK, I figured out how to have Outlook open displaying the inbox and I have changed the program so it does not open the individual emails and it loops through the inbox to save them all. Now if if didn't present this error it would be working (except it needs to run on the email received event). I don't know how to attach the .bmp file so I will retype the error message: " A program is trying to access data from Outlook that may include address book information. Do you want to allow this? If this is unexpected, it may be a virus and you should choose"No"." |
#6
|
|||
|
|||
![]() Thanks for lead Sue, I will read this carefully and change what needs to. |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Help with Saving Attachment with VBA from Rules | Murphybp2 | Outlook and VBA | 4 | August 21st 07 02:16 PM |
HTM body and an attachment | Edwin | Outlook - Using Forms | 0 | January 23rd 07 01:39 PM |
Saving Attachments using VBA and parsing information from subject/body | [email protected] | Outlook and VBA | 3 | December 12th 06 07:56 PM |
Read Attachment - Body | Vadhimoo | Outlook and VBA | 1 | December 4th 06 05:59 AM |
saving email without attachment | Happy | Outlook Express | 3 | January 24th 06 05:34 PM |