Macro won't work

exandbeyond

New Member
Joined
Feb 25, 2014
Messages
8
Can you someone tell me what's wrong?

Code:
Sub GetMailInfo(Path As String)

    Dim MyOutlook As Outlook.Application
    Dim msg As Outlook.MailItem
    Dim x As Namespace

    Set MyOutlook = New Outlook.Application
    Set x = MyOutlook.GetNamespace("MAPI")

    FileList = GetFileList(Path + "*.msg")


    row = 1

    While row <= UBound(FileList)

        Set msg = x.OpenSharedItem(Path + FileList(row))

        Cells(row + 1, 1) = msg.Subject
        Cells(row + 1, 2) = msg.Sender
        Cells(row + 1, 3) = msg.CC
        Cells(row + 1, 4) = msg.To
        Cells(row + 1, 5) = msg.SentOn


        row = row + 1
    Wend

End Sub

If uses this function:

Code:
Function GetFileList(FileSpec As String) As Variant
'   Taken from http://spreadsheetpage.com/index.php/tip/getting_a_list_of_file_names_using_vba/
'   Returns an array of filenames that match FileSpec
'   If no matching files are found, it returns False

    Dim FileArray() As Variant
    Dim FileCount As Integer
    Dim FileName As String

    On Error GoTo NoFilesFound

    FileCount = 0
    FileName = Dir(FileSpec)
    If FileName = "" Then GoTo NoFilesFound

'   Loop until no more matching files are found
    Do While FileName <> ""
        FileCount = FileCount + 1
        ReDim Preserve FileArray(1 To FileCount)
        FileArray(FileCount) = FileName
        FileName = Dir()
    Loop
    GetFileList = FileArray
    Exit Function

'   Error handler
    NoFilesFound:
        GetFileList = False
End Function
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
It's because you have (Path as String). Why are you passing the variable "Path" through this macro? Coding like this means that another subroutine must submit a value to Path before you run GetMailInfo. Does that make sense?
 
Upvote 0
It's because you have (Path as String). Why are you passing the variable "Path" through this macro? Coding like this means that another subroutine must submit a value to Path before you run GetMailInfo. Does that make sense?

Somewhat. So I am I guessing I will have to Declare Path as a String with in this Sub Routine i.e. Dim Path as String. Then recode in a way so it will get the Path some how. Thank you.
 
Last edited:
Upvote 0
Yep, you're on the right track! Let me know if you need any help getting your Path. Just start off by declaring your subroutine as: Sub GetMailInfo()
 
Upvote 0
Yep, you're on the right track! Let me know if you need any help getting your Path. Just start off by declaring your subroutine as: Sub GetMailInfo()

Thanks Chris Macro. I will work on this today if I have time. I am hoping to have something working by tuesday of next week. I am sure I will get stuck so I will try to post what I have today or monday. I literally have hundreds of emails to put on a spreadsheet for my monthly report and my report is due on the 24th.
 
Upvote 0
I haven't had to time to get to this. Does anyone have a macro that gets the Subject,Sender,To, and SentOn from a msg file to excel?
 
Upvote 0

Forum statistics

Threads
1,216,750
Messages
6,132,499
Members
449,730
Latest member
SeanHT

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