VBA Editor Keeps Opening On Its Own-Outlook 07

D

Dave_V

I've created a script that automatically saves attachments to a specified
folder, using the date portion of the ReceivedTime to name the attachment
(the email arrives daily with the attachment always titled "mail.rtf"

I've setup a rule to run this script when the appropriate email arrives. It
works beautifully. However, since I started utilizing this script, the VBA
editor will open on its own. It happens throughout the day, not necessarily
when the email arrives that triggers the script (that comes at 7:45am, but
the VBA window pops up numerous times during the day). I notice that when it
popsup on it's own, it doesn't have the full interface -- things like the
menu and toolbars at the top aren't displayed.

Any ideas why this is happening, and how to stop it?

Here is the script:
Sub SaveBAIFileAttachmentsToDisk(olkMessage As Outlook.MailItem)
Dim olkAttachment As Outlook.Attachment, _
objFSO As Object, _
strRootFolderPath As String, _
strFilename As String

'Change the path on the following line to the folder you want the
attachments save in
strRootFolderPath = "C:\attachments\Daily BAI File Archive\"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set olkSourceFolder = Application.ActiveExplorer.CurrentFolder
If olkMessage.Attachments.Count > 0 Then
For Each olkAttachment In olkMessage.Attachments
'build the filename based on the date
strFilename = Format(olkMessage.ReceivedTime, "yyyy-mm-dd") &
".rtf"
intCount = 0
Do While True
If objFSO.FileExists(strRootFolderPath & strFilename) Then
intCount = intCount + 1
strFilename = "Copy (" & intCount & ") of " & strFilename
Else
Exit Do
End If
Loop
olkAttachment.SaveAsFile strRootFolderPath & strFilename
Next
End If
Set objFSO = Nothing
Set olkAttachment = Nothing
Set olkMessage = Nothing
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top