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

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
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,224,875
Messages
6,181,514
Members
453,050
Latest member
Obil

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