Consulting

Results 1 to 17 of 17

Thread: To read Outlook Mailbox

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    I modified my code but it is still not reading the mails or the attachments.
    The count is still zero

    Private Sub cmdOutlook_Click()
        Dim olApp As Object
        Set olApp = CreateObject("Outlook.Application")
        Dim olNs As NameSpace
        Dim Fldr As MAPIFolder
        Dim olMi As Object
        Set olMi = olApp.CreateItem(0)
        Dim olAtt As Outlook.Attachments
        Dim strFile As String
        Dim objSubject As String
        Dim strFolderpath As String
        Dim i As Long
        Dim objDestfolder As Outlook.Folder
        
        Set olNs = olApp.GetNamespace("MAPI")
        'strFolderpath = "S:\beData\prof_data"
        strFolderpath = "C:\Users\prasad.govindarajan\Testing"
         objSubject = olMi.Subject
        sreplace = "_"
        'create an array to loop through and replace any potential illegal characters
        For Each mychar In Array("/", "\", "^", "*", "%", "$", "#", "@", "~", "`", "{", "}", "[", "]", "|", ";", ":", ",", ".", "'", "+", "=", "?", "!", " ", Chr(34), "<", ">", "¦")
           objSubject = Replace(objSubject, mychar, sreplace)
        Next mychar
        ' Set the Attachment folder.
        strFolderpath = strFolderpath & "\Attachments\"
        Set objDestfolder = olNs.Folders.item("WeeklyProceedings Mailbox").Folders.item("Folders").Folders.item("Archive_Proc")
        
        Set olAtt = olMi.Attachments
        lngCount = olAtt.Count
        If lngCount > 0 Then
            For i = lngCount To 1 Step -1
                strFile = objSubject & ".XML"
        
                ' Combine with the path to the Temp folder.
                strFile = strFolderpath & strFile
        
                ' Save the attachment as a file.
                olAtt.item(i).SaveAsFile strFile
            Next i
           
            olMi.Body = olMi.Body & vbCrLf & "The file was processed " & Now()
                       
            olMi.Subject = "Processed - " & objSubject
            olMi.Save
     
        End If
        'olMi.Move objDestfolder
    'Next
     
    Set olAtt = Nothing
    Set olMi = Nothing
    Attached Files Attached Files
    Last edited by Aussiebear; 08-11-2023 at 12:32 PM. Reason: Added the code for others to see

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •