Share via

vba code help

Anonymous
2019-08-16T16:17:11+00:00

I am currently trying to use this vba code and am running in to an issue with it saying the line of

Set outlooknamespace = OutlookApp.GetNamespace("MAPI") is not working and I can not figure out why.

Sub getDataFromOutlook()

Dim OutlookApp As Outlook.Application

Dim OutlookNameSpace As Namespace

Dim Folder As MAPIFolder

Dim OutlookMail As Variant

Dim i As Integer

Set OutlookApp = New Outlook.Application

Set OutlookNameSpace = OutlookApp.GetNamespace("MAPI")

Set Folder = OutlookNameSpace.GetDefaultFoler(olFolderInbox).Folders("DDQ")

i = 1

For Each OutlookMail In Folder.Items

If OutlookMail.ReceivedTime >= Range("Email_Receipt_Date").Value Then

Range("email_subject").Offset(i, 0) = OutlookMail.Subject

Range("email_subject").Offset(i, 0).Columns.AutoFit

Range("email_subject").Offset(i, 0).VerticalAlignmant = xlTop

Range("email_Date").Offset(i, 0).Value = OutlookMail.ReceivedTime

Range("email_Date").Offset(i, 0).Columns.AutoFit

Range("email_Date").Offset(i, 0).VerticalAlignment = xlTop

Range("email_Sender").Offset(i, 0).Value = OutlookMail.SenderName

Range("email_Sender").Offset(i, 0).Columns.AutoFit

Range("email_Sender").Offset(i, 0).VertricalAlignment = xlTop

Range("email_Body").Offset(i, 0).Value = OutlookMail.Body

Range("email_Body").Offset(i, 0).Columns.AutoFit

Range("email_Body").Offset(i, 0).VertricalAlignment = xlTop

i = i + 1

End If

Next OutlookMail

Set Folder = Nothing

Set OutlookNameSpace = Nothing

Set OutlookApp = Nothing

End Sub

any help or suggestions would be appreciated. I got this code from a video I saw https://www.youtube.com/redirect?event=video_description&v=35g8J2mzdUY&redir_token=NxwnH_VmKtwOzqqPD_QZBTjc3q58MTU2NjA0ODU3NUAxNTY1OTYyMTc1&q=https%3A%2F%2Fwww.exceltrainingvideos.com%2Fget-data-from-outlook-into-excel-worksheet%2F

I am trying to get the Information from a sub folder titled DDQ under my Inbox. Not sure if that helps of not.

Thank you.

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

3 answers

Sort by: Most helpful
  1. Andreas Killer 144.1K Reputation points Volunteer Moderator
    2019-08-17T09:29:32+00:00

    Set Folder = OutlookNameSpace.GetDefaultFoler(olFolderInbox).Folders("DDQ")

    It's a typo, "Folder" not "Foler":

    Set Folder = OutlookNameSpace.GetDefaultFolder(olFolderInbox).Folders("DDQ")

    Andreas.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2019-08-16T16:46:03+00:00

    I am currently trying to use this vba code and am running in to an issue with it saying the line of

    Set outlooknamespace = OutlookApp.GetNamespace("MAPI") is not working and I can not figure out why.

    Sub getDataFromOutlook()

    Dim OutlookApp As Outlook.Application

    Dim OutlookNameSpace As Namespace

    Dim Folder As MAPIFolder

    Dim OutlookMail As Variant

    Dim i As Integer

    Set OutlookApp = New Outlook.Application

    Set OutlookNameSpace = OutlookApp.GetNamespace("MAPI")

    Set Folder = OutlookNameSpace.GetDefaultFoler(olFolderInbox).Folders("DDQ")

    i = 1

    For Each OutlookMail In Folder.Items

        If OutlookMail.ReceivedTime >= Range("Email_Receipt_Date").Value Then

            Range("email_subject").Offset(i, 0) = OutlookMail.Subject

            Range("email_subject").Offset(i, 0).Columns.AutoFit

            Range("email_subject").Offset(i, 0).VerticalAlignmant = xlTop

            Range("email_Date").Offset(i, 0).Value = OutlookMail.ReceivedTime

            Range("email_Date").Offset(i, 0).Columns.AutoFit

            Range("email_Date").Offset(i, 0).VerticalAlignment = xlTop

            Range("email_Sender").Offset(i, 0).Value = OutlookMail.SenderName

            Range("email_Sender").Offset(i, 0).Columns.AutoFit

            Range("email_Sender").Offset(i, 0).VertricalAlignment = xlTop

            Range("email_Body").Offset(i, 0).Value = OutlookMail.Body

            Range("email_Body").Offset(i, 0).Columns.AutoFit

            Range("email_Body").Offset(i, 0).VertricalAlignment = xlTop

            i = i + 1

        End If

    Next OutlookMail

    Set Folder = Nothing

    Set OutlookNameSpace = Nothing

    Set OutlookApp = Nothing

    End Sub

    any help or suggestions would be appreciated. I got this code from a video I saw https://www.youtube.com/redirect?event=video_description&v=35g8J2mzdUY&redir_token=NxwnH_VmKtwOzqqPD_QZBTjc3q58MTU2NjA0ODU3NUAxNTY1OTYyMTc1&q=https%3A%2F%2Fwww.exceltrainingvideos.com%2Fget-data-from-outlook-into-excel-worksheet%2F

    I am trying to get the Information from a sub folder titled DDQ under my Inbox. Not sure if that helps of not.

    Thank you.

    Was this answer helpful?

    0 comments No comments
  3. Andreas Killer 144.1K Reputation points Volunteer Moderator
    2019-08-16T16:31:12+00:00

    Add the line

    Option Explicit
    

    at the top of the module, then click Debug \ Compile

    What error message do you get? (Post a screenshot)

    Andreas.

    Was this answer helpful?

    0 comments No comments