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 - Sub auto_open()
-
Dim ns As NameSpace
-
Dim Inbox As MAPIFolder
-
Dim Item As Object
-
Dim Atmt As Attachment
-
Dim FileName As String
-
Dim i As Integer
-
-
Set ns = GetNamespace("MAPI")
-
Set Inbox = ns.GetDefaultFolder(olFolderInbox)
-
i = 0
-
If Inbox.Items.Count = 0 Then
-
MsgBox "There are no messages in the Inbox.", vbInformation, _
-
"Nothing Found"
-
Exit Sub
-
End If
-
For Each Item In Inbox.Items
-
For Each Atmt In Item.Attachments
-
FileName = "C:\Email Attachments\" & Atmt.FileName
-
Atmt.SaveAsFile FileName
-
i = i + 1
-
Next Atmt
-
Next Item
-
If i > 0 Then
-
MsgBox "I found " & i & " attached files." _
-
& vbCrLf & "I have saved them into the C:\Email Attachments folder." _
-
& vbCrLf & vbCrLf & "Have a nice day.", vbInformation, "Finished!"
-
Else
-
MsgBox "I didn't find any attached files in your mail.", vbInformation, _
-
"Finished!"
-
End If
-
End Sub
Regards
Seshu
6 2774
Some one please look into this
Regards
Seshu
Assuming you only need to check for attachments at startup and everytime you get mail instead of every 5 minutes, this might work: - Private Sub Application_Startup()
-
Call SaveAttachments()
-
End Sub
-
-
Private Sub Application_NewMail()
-
Call SaveAttachments()
-
End Sub
-
-
Sub SaveAttachments()
-
Dim ns As NameSpace
-
Dim Inbox As MAPIFolder
-
Dim Item As Object
-
Dim Atmt As Attachment
-
Dim FileName As String
-
Dim i As Integer
-
-
Set ns = GetNamespace("MAPI")
-
Set Inbox = ns.GetDefaultFolder(olFolderInbox)
-
i = 0
-
If Inbox.Items.Count = 0 Then
-
MsgBox "There are no messages in the Inbox.", vbInformation, _
-
"Nothing Found"
-
Exit Sub
-
End If
-
For Each Item In Inbox.Items
-
For Each Atmt In Item.Attachments
-
FileName = "C:\Email Attachments\" & Atmt.FileName
-
Atmt.SaveAsFile FileName
-
i = i + 1
-
Next Atmt
-
Next Item
-
If i > 0 Then
-
MsgBox "I found " & i & " attached files." _
-
& vbCrLf & "I have saved them into the C:\Email Attachments folder." _
-
& vbCrLf & vbCrLf & "Have a nice day.", vbInformation, "Finished!"
-
Else
-
MsgBox "I didn't find any attached files in your mail.", vbInformation, _
-
"Finished!"
-
End If
-
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.
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
(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.
It should look something like this - Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
-
Dim i&
-
Dim itemID
-
Dim oMail As MailItem
-
Dim Atmt As Attachment
-
Dim FileName$
-
Dim arIDs() As String
-
-
arIDs = Split(EntryIDCollection, ",")
-
-
For Each itemID In arIDs
-
On Error Resume Next 'if item is not a "MailItem" following line would fail
-
Set oMail = Application.Session.GetItemFromID(itemID)
-
On Error GoTo 0
-
-
If Not oMail Is Nothing Then
-
For Each Atmt In oMail.Attachments
-
FileName = "D:\Email Attachments\" & Atmt.FileName
-
Atmt.SaveAsFile FileName
-
Next Atmt
-
Set oMail = Nothing
-
End If
-
Next
-
End Sub
-
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."
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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();...
|
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...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
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
|
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...
|
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,...
|
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...
|
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...
| |