PDA

View Full Version : Outlook vba help



malleshg24
01-01-2018, 11:05 PM
Hi Team,
I am creating a vba outlook macro ,

my task is saving daily report file with specific subject line in D drive.
I am creating a macro for a team. and this macro works only when the report is in below subfolder.
Set fol = ons.GetDefaultFolder(olFolderInbox).Folders("report")

But all my colleagues having different subfolders and its name. and it wont work on their PC.

So here I am looking for a code, It should check the report in default folder inbox.
and if not found then check all subfolder and save the report.:think:

plz assist. Thanks in advance for your precious time.:help

Sub Saving_DBR_Report()
Dim olook As Outlook.Application
Set olook = New Outlook.Application
Dim ons As Outlook.Namespace
Set ons = olook.GetNamespace("MAPI")
Dim omail As Outlook.MailItem
Set omail = olook.CreateItem(olMailItem)
Dim fol As Outlook.Folder
Set fol = ons.GetDefaultFolder(olFolderInbox).Folders("report")
Dim atmt As Outlook.Attachment
Dim z As String
For Each omail In fol.Items
z = omail.Subject
If z Like "Daily Report file*" Then
For Each atmt In omail.Attachments

If atmt.Filename Like "DBR*" Then
atmt.SaveAsFile "D:/" & atmt.Filename
End If
Next
End If
Next
End Sub


Thanks
Mallesh