Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OUTLOOK - Write Rules/Macros for Personal or General Mail folders

Status
Not open for further replies.

Sdirby

Technical User
Mar 8, 2004
18
US
Good Morning,

I am wondering how i can have a macro or rule run on a folder that is NOT in my inbox. For instance, My company has a General Information mailbox we'll say it's General.Information@123.net. Now i've got rules set to run on my personal inbox to parse my mail out, but what i really need is for it to run on that general Mailbox. If i need to clarify more just let me know. Here's the code i'm using, i cant figure out how to modify it to access a mailbox other than my inbox.



Sub Application_Startup()
Dim myOlApp As Outlook.Application
Dim myNameSpace As NameSpace
Dim myInbox As MAPIFolder
Dim objDestinationFolder As MAPIFolder
Dim myMessages As Items
Dim myItem As Outlook.MailItem
Dim myPos As Integer
Dim sDate As Date
Dim myAttach As Outlook.Attachments
Dim FileName As String
Dim t As Long, j As Long, y As Long, tDate As String
Dim DateCheck As Date
Dim AttachCount As Long
Dim sSubject As String
Dim sName As String

On Error GoTo Err_Check

Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNamespace("MAPI")
set myinbox = mynamespace.
Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox)
Set objDestinationFolder = myInbox.Folders("")
Set myMessages = myInbox.Items
Set myItem = myMessages.GetFirst
j = myInbox.Items.Count

Do While t < j
t = t + 1
If myItem.UnRead = True Then
sSubject = LCase(myItem.Subject)
myPos = InStr(sSubject, "payoffs")
If myPos > 0 Then
'sName = myItem.SenderName
'sName = Trim(sName)
sDate = myItem.ReceivedTime
Set myAttach = myItem.Attachments
y = myItem.Attachments.Count

For i = 1 To y
FileName = myAttach.Item(i).FileName
FileType = LCase(Right(FileName, 3))
If FileType = "xls" Then
'tDate = Format(sDate, "mm/dd/yy")
myAttach.Item(i).SaveAsFile ""
End If
AttachCount = AttachCount + 1
Next i
End If
End If
Set myItem = myMessages.GetNext
Loop
Set myOlApp = Nothing
Set myNameSpace = Nothing
Set myInbox = Nothing
Set myMessages = Nothing
Set myItem = Nothing
MsgBox "There was/were " & AttachCount & " attachment(s) saved."
Exit Sub
Err_Check:
If Err.Number = 13 Then
Resume Next
Else
MsgBox Err.Number & vbCrLf & vbCrLf & Err.Description
End If
End Sub


The code has been modified some so if it's not perfect i apologize, its been a long morning. :)
Thanks for all you Guys (and Gals) do. I'd appreciate any help you give. Have a great day!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top