exandbeyond
New Member
- Joined
- Feb 25, 2014
- Messages
- 8
Can you someone tell me what's wrong?
If uses this function:
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