Outlook VBA code crashes Outlook!

Status
Not open for further replies.

the_goldfish

Beta member
Messages
2
I know that it is bad form to post a question first post, but I am tearing my hair out over this...

I wrote a small VBA script to strip sender addresses from emails and put them into a .TXT file on the desktop. It runs OK on my Outlook 2003, but when run on my bosses machine, we get the following error:

"Outlook experienced a serious error the last time the add-in..." thats all i got before the window was closed. The add-in mentioned was a VBA add-in.

Here is the code:
Sub GetUnsubAddresses()
Dim myOlApp As Outlook.Application
Dim mpfBox As Outlook.MAPIFolder
Dim obj As Outlook.MailItem
Dim i As Integer
Dim myFileName
Set myOlApp = CreateObject("Outlook.Application")
Set mpfBox = myOlApp.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Folders("mailboxAtZoomdirect")

'create text file to write unsubs to
Set ObjFSO = CreateObject("Scripting.FileSystemObject")
Set ObjFile = ObjFSO.CreateTextFile("C:\Documents and Settings\chris.TEMPEST\Desktop\unsubs.txt")
' Loop all items in the Inbox\Test Folder
For i = 1 To mpfBox.Items.Count
If mpfBox.Items(i).Class = olMail Then
Set obj = mpfBox.Items.Item(i)

'write the unsubs to text file
ObjFile.WriteLine obj.SenderEmailAddress
End If
Next

'close text file object
ObjFile.Close
Set ObjFile = Nothing
Set ObjFSO = Nothing

End Sub
Any ideas on WHY this is happening would be greatly appeciated. Im at my wits end!! Thank you in advance, Chris.
 
Status
Not open for further replies.
Back
Top Bottom