Outlook : Code

chandrashekar

Well-known Member
Joined
Jul 15, 2005
Messages
529
Office Version
  1. 365
Platform
  1. Windows
Hello,

Could you please help to get outlook code from the folder Test- Under CI Dashboard.

1698052720576.png

Regards,
Chandrashekar B
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Assuming that your main folder is named "Outlook", you can access your Test folder as follows....

VBA Code:
    Dim outlookApp As Object
    Set outlookApp = CreateObject("Outlook.Application")
    
    Dim outlookNamespace As Object
    Set outlookNamespace = outlookApp.getnamespace("MAPI")
    
    Dim testFolder As Object
    Set testFolder = outlookNamespace.Folders("Outlook").Folders("CI Dashboard").Folders("Test") 'change the name of the main folder accordingly

Hope this helps!
 
Upvote 0
Assuming that your main folder is named "Outlook", you can access your Test folder as follows....

VBA Code:
    Dim outlookApp As Object
    Set outlookApp = CreateObject("Outlook.Application")
   
    Dim outlookNamespace As Object
    Set outlookNamespace = outlookApp.getnamespace("MAPI")
   
    Dim testFolder As Object
    Set testFolder = outlookNamespace.Folders("Outlook").Folders("CI Dashboard").Folders("Test") 'change the name of the main folder accordingly

Hope this helps!
Hello,
Sorry for late reply. Do u have a full code where I can download attachments to a folder.

Regards,
Chandrashekar B
 
Upvote 0
The following macro will loop through each item in your Test folder. And, for each item, it first checks to make sure that it's a MailItem, then it downloads any and all attachments from the MailItem to the specified folder (change as desired where specified in the code). Note that if a file by the same name already exists in the destination folder, it will be overwritten.

VBA Code:
Option Explicit

Sub DownloadEmailAttachments()

    Dim saveToFolderName As String
    saveToFolderName = "c:\users\domenic\desktop\" 'change the destination folder name accordingly
    If Right(saveToFolderName, 1) <> "\" Then
        saveToFolderName = saveToFolderName & "\"
    End If

    Dim outlookApp As Object
    Set outlookApp = CreateObject("Outlook.Application")
 
    Dim outlookNamespace As Object
    Set outlookNamespace = outlookApp.getnamespace("MAPI")
 
    Dim testFolder As Object
    Set testFolder = outlookNamespace.Folders("Outlook").Folders("CI Dashboard").Folders("Test") 'change the name of the main folder accordingly
   
    Dim outlookFolderItem As Variant
    Dim outlookEmailAttachment As Object
    For Each outlookFolderItem In testFolder.items
        If TypeName(outlookFolderItem) = "MailItem" Then
            For Each outlookEmailAttachment In outlookFolderItem.attachments
                outlookEmailAttachment.SaveAsFile saveToFolderName & outlookEmailAttachment.Filename
            Next outlookEmailAttachment
        End If
    Next outlookFolderItem
   
    Set testFolder = Nothing
    Set outlookNamespace = Nothing
    Set outlookApp = Nothing
   
    MsgBox "Completed!", vbInformation
   
End Sub

Hope this helps!
 
Last edited:
Upvote 0
The following macro will loop through each item in your Test folder. And, for each item, it first checks to make sure that it's a MailItem, then it downloads any and all attachments from the MailItem to the specified folder (change as desired where specified in the code). Note that if a file by the same name already exists in the destination folder, it will be overwritten.

VBA Code:
Option Explicit

Sub DownloadEmailAttachments()

    Dim saveToFolderName As String
    saveToFolderName = "c:\users\domenic\desktop\" 'change the destination folder name accordingly
    If Right(saveToFolderName, 1) <> "\" Then
        saveToFolderName = saveToFolderName & "\"
    End If

    Dim outlookApp As Object
    Set outlookApp = CreateObject("Outlook.Application")
 
    Dim outlookNamespace As Object
    Set outlookNamespace = outlookApp.getnamespace("MAPI")
 
    Dim testFolder As Object
    'Set testFolder = outlookNamespace.Folders("Outlook").Folders("CI Dashboard").Folders("Test") 'change the name of the main folder accordingly
   
    Dim outlookFolderItem As Variant
    Dim outlookEmailAttachment As Object
    For Each outlookFolderItem In testFolder.items
        If TypeName(outlookFolderItem) = "MailItem" Then
            For Each outlookEmailAttachment In outlookFolderItem.attachments
                outlookEmailAttachment.SaveAsFile saveToFolderName & outlookEmailAttachment.Filename
            Next outlookEmailAttachment
        End If
    Next outlookFolderItem
   
    Set testFolder = Nothing
    Set outlookNamespace = Nothing
    Set outlookApp = Nothing
   
    MsgBox "Completed!", vbInformation
   
End Sub

Hope this helps!
Thank you.

Regards,
Chandrashekar B
 
Upvote 0
The following macro will loop through each item in your Test folder. And, for each item, it first checks to make sure that it's a MailItem, then it downloads any and all attachments from the MailItem to the specified folder (change as desired where specified in the code). Note that if a file by the same name already exists in the destination folder, it will be overwritten.

VBA Code:
Option Explicit

Sub DownloadEmailAttachments()

    Dim saveToFolderName As String
    saveToFolderName = "c:\users\domenic\desktop\" 'change the destination folder name accordingly
    If Right(saveToFolderName, 1) <> "\" Then
        saveToFolderName = saveToFolderName & "\"
    End If

    Dim outlookApp As Object
    Set outlookApp = CreateObject("Outlook.Application")
 
    Dim outlookNamespace As Object
    Set outlookNamespace = outlookApp.getnamespace("MAPI")
 
    Dim testFolder As Object
    Set testFolder = outlookNamespace.Folders("Outlook").Folders("CI Dashboard").Folders("Test") 'change the name of the main folder accordingly
  
    Dim outlookFolderItem As Variant
    Dim outlookEmailAttachment As Object
    For Each outlookFolderItem In testFolder.items
        If TypeName(outlookFolderItem) = "MailItem" Then
            For Each outlookEmailAttachment In outlookFolderItem.attachments
                outlookEmailAttachment.SaveAsFile saveToFolderName & outlookEmailAttachment.Filename
            Next outlookEmailAttachment
        End If
    Next outlookFolderItem
  
    Set testFolder = Nothing
    Set outlookNamespace = Nothing
    Set outlookApp = Nothing
  
    MsgBox "Completed!", vbInformation
  
End Sub

Hope this helps!
Hello,

Thank you. It is working fine.

Regards,
Chandrashekar B
 
Upvote 0

Forum statistics

Threads
1,223,929
Messages
6,175,455
Members
452,643
Latest member
gjcase

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top