PDA

View Full Version : macro in outlook 2003



sgtschultz
05-16-2012, 11:35 AM
Our computers were recently removed from a network domain. One of our computers was also being used to receive faxes. The faxes come in as Tiff files into a folder on the desktop. A macro had been written (not by me) in Outlook that moved the files from the folder in to Outlook's inbox, and then sent them as an attachment in a email to a distribution list.

When we were taken off the domain, the code was no longer there, but i had a copy of it. We set up a new email account, and I pasted in the code, but it doesn't work. I don't get an error, it just doesn't do anything. The old email was on Microsoft Exchange Server, now we are using a POP server (if that matters)

We are using XP and Outlook 2003.

I know nothing about coding or macros, but I am hoping there is some obvious easy solution to this -- or an alternate solution to dispersing faxes to multiple email addresses.

Here is the code that i pasted in, thanks in advance for any help:


Private Sub Application_Startup() 'do when application starts
EnableTimer 60000, Me '60000 milliseconds (= 1 minute)
End Sub

Public Sub Timer()
' This code is Called from the timer
Dim varFileArray As Variant
Dim lngI As Long
Dim strDirName As String
Dim flname As String
Dim flLocation As String


Const NO_FILES_IN_DIR As Long = 9
Const INVALID_DIR As Long = 13

On Error GoTo Test_Err

strDirName = "C:\Documents and Settings\Tandem New Account\Desktop\FAXRECD"
varFileArray = GetAllFilesInDir(strDirName)
For lngI = 0 To UBound(varFileArray)
flname = varFileArray(lngI)

Dim objMsg As MailItem
' create new outgoing message
Set objMsg = Application.CreateItem(olMailItem)
' e-mail information
objMsg.To = "xxxxxxxxxxxx@gmail.com"
objMsg.Subject = "FAX FAX FAX"
'add attachment
objMsg.Attachments.Add (strDirName & "\" & flname)
' send the message and move to sent items folder
objMsg.Send
'create file location string
flLocation = strDirName & "\" & flname
'First remove readonly attribute, if set
SetAttr flLocation, vbNormal
'Then delete the file
Kill flLocation
'reset the variable to Null
Set objMsg = Nothing
'move to next record
Next lngI
Test_Err:
'If no files exist in the desiginated
End Sub

Private Sub Application_Quit() 'do when application closes
DisableTimer
End Sub

Crocus Crow
05-23-2012, 03:58 PM
Start by commenting out the On Error statement and see if any errors occur when run. If error(s) occur, write code which anticipates the error rather than relying on On Error. Have you defined the EnableTimer, DisableTimer and GetAllFilesInDir procedures in the Outlook module?

JP2112
05-23-2012, 07:16 PM
Welcome to the forum. Please use
tags when posting code.

A while back I wrote some code that creates a task reminder, then continues to create new task reminders every N minutes:

http://www.vbaexpress.com/forum/showthread.php?t=35985

In the BeforeReminderShow Event (http://msdn.microsoft.com/en-us/library/aa157798(v=office.10).aspx), you would place your code that checks the folder for new files and emails them out.

skatonni
06-28-2012, 02:48 PM
Looks like some of the code is missing.

http://vboffice.net/sample.html?lang=en&mnu=2&smp=4&cmd=showitem