Why would this code work intermittently

D

Dale

I have the following:

Public Sub SAVESALES() 'LoopMailFolder()

Dim oSel As Outlook.Selection
Dim obj As Object
Dim cnt As Long
Dim SALEDate As String

Set oSel = Application.ActiveExplorer.Selection
cnt = oSel.Count

SALEDate = InputBox("What is today's date?")

If cnt = 15 Then
For i = 1 To cnt
Set obj = oSel(i)
If obj.Class = olMail Then
ExportMailToTxt obj, Chr$(96 + i), SALEDate
End If
Next
End If

Shell "d:\Program Files\UltraEdit\uedit32.exe Q:\efiles\email\SALE" &
SALEDate & "*.txt", vbNormalFocus

End Sub

Public Function ExportMailToTxt(oMail As Object, _
sExt As String, sDate As String _
) As Boolean
On Error Resume Next
Dim sPath As String: sPath = "Q:\efiles\email\" '"c:\"
Dim sName As String

sName = "SALE" & sDate _
& sExt & ".txt"
oMail.SaveAs sPath & sName, olTXT ' errs here when On Error statment is
disabled.
ExportMailToTxt = (Err.Number = 0)
End Function


This code works fine on my computer but works intermittently if at all on
the computer it must work on. I get the a run-time error when the "On
Error" statement in the Function is disabled. The error says "method
'SaveAs' of object 'MailItem' failed".

One thought is the version of outlook. Both computers have Outlook 2003 SP2
althought the other computer seems to be somewhat more up-to-date. It is
version 11.8010.8036. My computer is version 11.8010..6568. Possibly an
update broke something?

Can anyone explain what's happening?

Regards
Dale
 
M

Michael Bauer [MVP - Outlook]

Am Fri, 8 Sep 2006 15:45:48 -0500 schrieb Dale:

Dale, the Path must exist already. With MkDir you can create the path but
just folder for folder, i.e. first you´d create Q:\efiles, then
Q:\efiles\email
 
J

JaleDones

Thanx for the reply Michael,

Q:\efiles\email is a path which will always exist on my network. Any other
thoughts?

Regards
Dale
 
M

Michael Bauer [MVP - Outlook]

Am Sat, 9 Sep 2006 16:48:57 -0500 schrieb JaleDones:

If it fails then please check the value of the variable sName, probably it
contains unallowed characters.
 
D

Dale

Michael,

I stepped thru the code and did not see anything out of the ordinary for the
value of sName. But low and behold it worked as necessary this time on the
machine it should be run on. I do not believe our naming convention would
ever cause a problem do you? All sName should ever be valued at would be
"SALE" + the date (something like today 0911) plus the lower case letter a
thru o. Also, just because it ran today, doesn't make me think it will run
on another day.

So if I am correct, do you have any other thoughts? Or..... do you think
there still could be a problem with the way I am naming my files?

Regards
Dale
 
M

Michael Bauer [MVP - Outlook]

Am Mon, 11 Sep 2006 13:23:33 -0500 schrieb Dale:

Saving any message as a txt should always work. The only problems I can
think of are:
- no permission to write/create files in that directory
- the directory doesn´t exist
- the file name contains invalid characters.

Because you let the user enter the date manually (input box) - yes, I think
there could be the error.
 
D

Dale

Michael,

I guess I could try coding something that pulls from the system date. I'll
try searching for some coding examples. Unless you have something readily
at hand.

Regards
Dale
 
M

Michael Bauer [MVP - Outlook]

Am Tue, 12 Sep 2006 08:07:58 -0500 schrieb Dale:

If you really want to know just the current date, that´s returned by the
Date function.

SALEDate = Date
 

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