473,387 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How run a macro when i open my out look (with out going to macros and running)

seshu
156 100+
Hi Everybody
I wrote a small macro in my outlook macros it is working fine but i want to run that automatically when i open my outlook and once after opening it
i want to refresh my out look for every five minutes so that my macro will run for every five mins
and here is the code what i wrote
Expand|Select|Wrap|Line Numbers
  1. Sub auto_open()
  2. Dim ns As NameSpace
  3.  Dim Inbox As MAPIFolder
  4.  Dim Item As Object
  5.  Dim Atmt As Attachment
  6.  Dim FileName As String
  7.  Dim i As Integer
  8.  
  9.   Set ns = GetNamespace("MAPI")
  10.  Set Inbox = ns.GetDefaultFolder(olFolderInbox)
  11.  i = 0
  12. If Inbox.Items.Count = 0 Then
  13.     MsgBox "There are no messages in the Inbox.", vbInformation, _
  14.            "Nothing Found"
  15.     Exit Sub
  16.  End If
  17.   For Each Item In Inbox.Items
  18.       For Each Atmt In Item.Attachments
  19.        FileName = "C:\Email Attachments\" & Atmt.FileName
  20.        Atmt.SaveAsFile FileName
  21.        i = i + 1
  22.     Next Atmt
  23.  Next Item
  24.  If i > 0 Then
  25.     MsgBox "I found " & i & " attached files." _
  26.        & vbCrLf & "I have saved them into the C:\Email Attachments folder." _
  27.        & vbCrLf & vbCrLf & "Have a nice day.", vbInformation, "Finished!"
  28.  Else
  29.     MsgBox "I didn't find any attached files in your mail.", vbInformation, _
  30.     "Finished!"
  31. End If
  32. End Sub
Regards
Seshu
Apr 28 '07 #1
6 2774
seshu
156 100+
Some one please look into this

Regards
Seshu
Apr 30 '07 #2
danp129
323 Expert 256MB
Assuming you only need to check for attachments at startup and everytime you get mail instead of every 5 minutes, this might work:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Application_Startup()
  2.     Call SaveAttachments()
  3. End Sub
  4.  
  5. Private Sub Application_NewMail()
  6.     Call SaveAttachments()
  7. End Sub
  8.  
  9. Sub SaveAttachments()
  10.  Dim ns As NameSpace
  11.  Dim Inbox As MAPIFolder
  12.  Dim Item As Object
  13.  Dim Atmt As Attachment
  14.  Dim FileName As String
  15.  Dim i As Integer
  16.  
  17.   Set ns = GetNamespace("MAPI")
  18.  Set Inbox = ns.GetDefaultFolder(olFolderInbox)
  19.  i = 0
  20. If Inbox.Items.Count = 0 Then
  21.     MsgBox "There are no messages in the Inbox.", vbInformation, _
  22.            "Nothing Found"
  23.     Exit Sub
  24.  End If
  25.   For Each Item In Inbox.Items
  26.       For Each Atmt In Item.Attachments
  27.        FileName = "C:\Email Attachments\" & Atmt.FileName
  28.        Atmt.SaveAsFile FileName
  29.        i = i + 1
  30.     Next Atmt
  31.  Next Item
  32.  If i > 0 Then
  33.     MsgBox "I found " & i & " attached files." _
  34.        & vbCrLf & "I have saved them into the C:\Email Attachments folder." _
  35.        & vbCrLf & vbCrLf & "Have a nice day.", vbInformation, "Finished!"
  36.  Else
  37.     MsgBox "I didn't find any attached files in your mail.", vbInformation, _
  38.     "Finished!"
  39. End If
  40. End Sub

Personally I would hate that script to run every time I got new mail or every 5 minutes. You might Google Application_NewMailEx(ByVal EntryIDCollection As String) event and see if it's possible to only scan the new messages instead of the entire inbox on every new message, it probably is. You might also prompt the user if they want to scan their mailbox in the Application_Startup sub.
May 2 '07 #3
seshu
156 100+
so you say that insted of downloading all the attachments again and again you are asking me to download only the new attachments thank you that was a good idea but the thing is i dont how to differentiate the new one with the old one programically but once after seeing your suggestuion if i write the save attachment code in new mail procedure we can down load only the new down load attachments is it true if so what is this id collection please give me a small explination


Regards
Seshu
May 2 '07 #4
Killer42
8,435 Expert 8TB
(Wow! Thought I was looking in a mirror then, when I saw the avatar...;))

What danp129 suggested was to "Google Application_NewMailEx(ByVal EntryIDCollection As String) event and see if it's possible to only scan the new messages". Sounds like sound advice, to me.
May 2 '07 #5
danp129
323 Expert 256MB
It should look something like this

Expand|Select|Wrap|Line Numbers
  1. Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
  2.     Dim i&
  3.     Dim itemID
  4.     Dim oMail As MailItem
  5.     Dim Atmt As Attachment
  6.     Dim FileName$
  7.     Dim arIDs() As String
  8.  
  9.     arIDs = Split(EntryIDCollection, ",")
  10.  
  11.     For Each itemID In arIDs
  12.         On Error Resume Next 'if item is not a "MailItem" following line would fail
  13.         Set oMail = Application.Session.GetItemFromID(itemID)
  14.         On Error GoTo 0
  15.  
  16.         If Not oMail Is Nothing Then
  17.             For Each Atmt In oMail.Attachments
  18.                 FileName = "D:\Email Attachments\" & Atmt.FileName
  19.                 Atmt.SaveAsFile FileName
  20.             Next Atmt
  21.             Set oMail = Nothing
  22.         End If
  23.     Next
  24. End Sub
  25.  
May 3 '07 #6
Denburt
1,356 Expert 1GB
FYI

Version info was not supplied so I thought I would mention.

Outlook 2003 and newer:
Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)


Older versions would use:

Private Sub Application_NewMail()

For more info you can visit MSDN, if you click on the following link it will provide you with more info and you can browse around to see examples and choose the version of your choice.
http://msdn2.microsoft.com/en-us/lib...ffice.10).aspx

In the article it mentions the following:
"since the NewMail event does not provide any details about the arriving item(s), you would have to keep track of what items were previously processed and, if you are also running Rules Wizard rules, examine multiple folders for new items."
May 3 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

25
by: Andrew Dalke | last post by:
Here's a proposed Q&A for the FAQ based on a couple recent threads. Appropriate comments appreciated X.Y: Why doesn't Python have macros like in Lisp or Scheme? Before answering that, a...
699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
6
by: Terry Bell | last post by:
We've had a very large A97 app running fine for the last seven years. I've just converted to SQL Server backend, which is being tested, but meanwhile the JET based version, running under terminal...
4
by: mvivar | last post by:
Hi everybody: This will be not easy to explain as my mother language is not english, so my apologies in advance if it sounds confusing. We have a database access 97 wich controls time of...
44
by: Simon Morgan | last post by:
Hi, Can somebody please help me grok the offsetof() macro? I've found an explanation on http://www.embedded.com/shared/printableArticle.jhtml?articleID=18312031 but I'm afraid it still...
17
by: sounak | last post by:
How could we get a macro name from a macro value such that in a header file #define a 100 #define b 200 now the source file will be such that the user gives 100 then the value is outputted as...
9
by: Francois Grieu | last post by:
Consider this macro // check if x, assumed of type unsigned char, is in range #define ISVALID(x) ((x)>=0x20 && (x)<=0x7E) Of course, this can't be safely used as in if (ISVALID(*p++)) foo();...
2
by: Chris Thomasson | last post by:
I was wondering if the 'SLINK_*' and 'SLIST_*' macros, which implement a simple singly-linked list, will produce _any_ possible undefined behavior: ____________________________ #include...
3
MMcCarthy
by: MMcCarthy | last post by:
Although some users find Macros simple and easy to use, there are some major limitations to using them. Although you can use macros to perform tasks, there is limited control on when and how those...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.