PC Review Forums Newsgroups Microsoft Outlook Microsoft Outlook VBA Programming Why did my macro suddenly stop working?

Reply

Why did my macro suddenly stop working?

 
Thread Tools Rate Thread
Old 14-03-2006, 03:48 PM   #1
Dale
Guest
 
Posts: n/a
Default Why did my macro suddenly stop working?


Hello all,

I have the following Outlook macro which has stopped working/is behaving
erratically between machines. It's always behaved perfectly before.

We have a client who sends 15 text files embedded in an email (not an
attachment). We have to save them out as text files to our network.

"If TypeOf obj Is Outlook.MailItem" seems to be the culprit.
ExportMailToTxt is just bypassed.

I have no idea why it would suddenly stop working. The only thing I can
come up with is something in the client's emails are playing havoc with the
macro.

Can anyone give me a clue to this puzzle?



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 TypeOf obj Is Outlook.MailItem Then ' ///Item is not recognized
as a MailItem?
ExportMailToTxt obj, Chr$(96 + i), SALEDate ' ///This code is
bypassed
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 Outlook.MailItem, _
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
ExportMailToTxt = (Err.Number = 0)
End Function



  Reply With Quote
Old 14-03-2006, 03:59 PM   #2
Dale
Guest
 
Posts: n/a
Default Re: Why did my macro suddenly stop working?

Sorry, in rereading my post I shoud have said"

We have a client who sends 15 emails. We have to save them out as text
files to our network


..

"Dale" <D-Man> wrote in message
news:u%23p4H73RGHA.4900@TK2MSFTNGP09.phx.gbl...
> Hello all,
>
> I have the following Outlook macro which has stopped working/is behaving
> erratically between machines. It's always behaved perfectly before.
>
> We have a client who sends 15 text files embedded in an email (not an
> attachment). We have to save them out as text files to our network.
>
> "If TypeOf obj Is Outlook.MailItem" seems to be the culprit.
> ExportMailToTxt is just bypassed.
>
> I have no idea why it would suddenly stop working. The only thing I can
> come up with is something in the client's emails are playing havoc with
> the macro.
>
> Can anyone give me a clue to this puzzle?
>
>
>
> 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 TypeOf obj Is Outlook.MailItem Then ' ///Item is not recognized
> as a MailItem?
> ExportMailToTxt obj, Chr$(96 + i), SALEDate ' ///This code is
> bypassed
> 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 Outlook.MailItem, _
> 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
> ExportMailToTxt = (Err.Number = 0)
> End Function
>
>
>



  Reply With Quote
Old 14-03-2006, 06:47 PM   #3
=?Utf-8?B?RXJpYyBMZWdhdWx0IFtNVlAgLSBPdXRsb29rXQ==
Guest
 
Posts: n/a
Default Re: Why did my macro suddenly stop working?

Change this:

If TypeOf obj Is Outlook.MailItem Then

to this:

If obj.Class = olMail Then

--
Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Dale" wrote:

> Sorry, in rereading my post I shoud have said"
>
> We have a client who sends 15 emails. We have to save them out as text
> files to our network
>
>
> ..
>
> "Dale" <D-Man> wrote in message
> news:u%23p4H73RGHA.4900@TK2MSFTNGP09.phx.gbl...
> > Hello all,
> >
> > I have the following Outlook macro which has stopped working/is behaving
> > erratically between machines. It's always behaved perfectly before.
> >
> > We have a client who sends 15 text files embedded in an email (not an
> > attachment). We have to save them out as text files to our network.
> >
> > "If TypeOf obj Is Outlook.MailItem" seems to be the culprit.
> > ExportMailToTxt is just bypassed.
> >
> > I have no idea why it would suddenly stop working. The only thing I can
> > come up with is something in the client's emails are playing havoc with
> > the macro.
> >
> > Can anyone give me a clue to this puzzle?
> >
> >
> >
> > 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 TypeOf obj Is Outlook.MailItem Then ' ///Item is not recognized
> > as a MailItem?
> > ExportMailToTxt obj, Chr$(96 + i), SALEDate ' ///This code is
> > bypassed
> > 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 Outlook.MailItem, _
> > 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
> > ExportMailToTxt = (Err.Number = 0)
> > End Function
> >
> >
> >

>
>
>

  Reply With Quote
Old 14-03-2006, 06:58 PM   #4
Dale
Guest
 
Posts: n/a
Default Re: Why did my macro suddenly stop working?

Thanx for the reply Eric.

What is the difference?

Dale

"Eric Legault [MVP - Outlook]" <elegaultZZZ@REMOVEZZZmvps.org> wrote in
message news:AC110A88-C0B3-4C8F-884D-0B2C15C5FF6C@microsoft.com...
> Change this:
>
> If TypeOf obj Is Outlook.MailItem Then
>
> to this:
>
> If obj.Class = olMail Then
>
> --
> Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
> Try Picture Attachments Wizard for Outlook:
> http://www.collaborativeinnovations.ca
> Blog: http://blogs.officezealot.com/legault/
>
>
> "Dale" wrote:
>
>> Sorry, in rereading my post I shoud have said"
>>
>> We have a client who sends 15 emails. We have to save them out as text
>> files to our network
>>
>>
>> ..
>>
>> "Dale" <D-Man> wrote in message
>> news:u%23p4H73RGHA.4900@TK2MSFTNGP09.phx.gbl...
>> > Hello all,
>> >
>> > I have the following Outlook macro which has stopped working/is
>> > behaving
>> > erratically between machines. It's always behaved perfectly before.
>> >
>> > We have a client who sends 15 text files embedded in an email (not an
>> > attachment). We have to save them out as text files to our network.
>> >
>> > "If TypeOf obj Is Outlook.MailItem" seems to be the culprit.
>> > ExportMailToTxt is just bypassed.
>> >
>> > I have no idea why it would suddenly stop working. The only thing I
>> > can
>> > come up with is something in the client's emails are playing havoc
>> > with
>> > the macro.
>> >
>> > Can anyone give me a clue to this puzzle?
>> >
>> >
>> >
>> > 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 TypeOf obj Is Outlook.MailItem Then ' ///Item is not
>> > recognized
>> > as a MailItem?
>> > ExportMailToTxt obj, Chr$(96 + i), SALEDate ' ///This code
>> > is
>> > bypassed
>> > 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 Outlook.MailItem, _
>> > 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
>> > ExportMailToTxt = (Err.Number = 0)
>> > End Function
>> >
>> >
>> >

>>
>>
>>



  Reply With Quote
Old 14-03-2006, 07:24 PM   #5
=?Utf-8?B?RXJpYyBMZWdhdWx0IFtNVlAgLSBPdXRsb29rXQ==
Guest
 
Posts: n/a
Default Re: Why did my macro suddenly stop working?

You got me - I'm not really sure. I've actually never seen Outlook.MailItem
used in an evaluative expression before, and I never use TypeOf with Outlook
(no particular reason). I'm just more comfortable using Class or
MessageClass properties to evaluate objects. Does the code make a difference
for you anyway?

--
Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Dale" wrote:

> Thanx for the reply Eric.
>
> What is the difference?
>
> Dale
>
> "Eric Legault [MVP - Outlook]" <elegaultZZZ@REMOVEZZZmvps.org> wrote in
> message news:AC110A88-C0B3-4C8F-884D-0B2C15C5FF6C@microsoft.com...
> > Change this:
> >
> > If TypeOf obj Is Outlook.MailItem Then
> >
> > to this:
> >
> > If obj.Class = olMail Then
> >
> > --
> > Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
> > Try Picture Attachments Wizard for Outlook:
> > http://www.collaborativeinnovations.ca
> > Blog: http://blogs.officezealot.com/legault/
> >
> >
> > "Dale" wrote:
> >
> >> Sorry, in rereading my post I shoud have said"
> >>
> >> We have a client who sends 15 emails. We have to save them out as text
> >> files to our network
> >>
> >>
> >> ..
> >>
> >> "Dale" <D-Man> wrote in message
> >> news:u%23p4H73RGHA.4900@TK2MSFTNGP09.phx.gbl...
> >> > Hello all,
> >> >
> >> > I have the following Outlook macro which has stopped working/is
> >> > behaving
> >> > erratically between machines. It's always behaved perfectly before.
> >> >
> >> > We have a client who sends 15 text files embedded in an email (not an
> >> > attachment). We have to save them out as text files to our network.
> >> >
> >> > "If TypeOf obj Is Outlook.MailItem" seems to be the culprit.
> >> > ExportMailToTxt is just bypassed.
> >> >
> >> > I have no idea why it would suddenly stop working. The only thing I
> >> > can
> >> > come up with is something in the client's emails are playing havoc
> >> > with
> >> > the macro.
> >> >
> >> > Can anyone give me a clue to this puzzle?
> >> >
> >> >
> >> >
> >> > 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 TypeOf obj Is Outlook.MailItem Then ' ///Item is not
> >> > recognized
> >> > as a MailItem?
> >> > ExportMailToTxt obj, Chr$(96 + i), SALEDate ' ///This code
> >> > is
> >> > bypassed
> >> > 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 Outlook.MailItem, _
> >> > 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
> >> > ExportMailToTxt = (Err.Number = 0)
> >> > End Function
> >> >
> >> >
> >> >
> >>
> >>
> >>

>
>
>

  Reply With Quote
Old 14-03-2006, 08:03 PM   #6
Dale
Guest
 
Posts: n/a
Default Re: Why did my macro suddenly stop working?

Eric,

It worked great on my machine. On the affected machine it gave a type
mismach error. F8'ing thru it was going to execute the ExportMailToTxt
function but apparently one of the items being passed was of the wrong type.

Dale


"Eric Legault [MVP - Outlook]" <elegaultZZZ@REMOVEZZZmvps.org> wrote in
message news:A74F19E1-2405-4E55-B04E-468EEE577E88@microsoft.com...
> You got me - I'm not really sure. I've actually never seen
> Outlook.MailItem
> used in an evaluative expression before, and I never use TypeOf with
> Outlook
> (no particular reason). I'm just more comfortable using Class or
> MessageClass properties to evaluate objects. Does the code make a
> difference
> for you anyway?
>
> --
> Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
> Try Picture Attachments Wizard for Outlook:
> http://www.collaborativeinnovations.ca
> Blog: http://blogs.officezealot.com/legault/
>
>
> "Dale" wrote:
>
>> Thanx for the reply Eric.
>>
>> What is the difference?
>>
>> Dale
>>
>> "Eric Legault [MVP - Outlook]" <elegaultZZZ@REMOVEZZZmvps.org> wrote in
>> message news:AC110A88-C0B3-4C8F-884D-0B2C15C5FF6C@microsoft.com...
>> > Change this:
>> >
>> > If TypeOf obj Is Outlook.MailItem Then
>> >
>> > to this:
>> >
>> > If obj.Class = olMail Then
>> >
>> > --
>> > Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
>> > Try Picture Attachments Wizard for Outlook:
>> > http://www.collaborativeinnovations.ca
>> > Blog: http://blogs.officezealot.com/legault/
>> >
>> >
>> > "Dale" wrote:
>> >
>> >> Sorry, in rereading my post I shoud have said"
>> >>
>> >> We have a client who sends 15 emails. We have to save them out as
>> >> text
>> >> files to our network
>> >>
>> >>
>> >> ..
>> >>
>> >> "Dale" <D-Man> wrote in message
>> >> news:u%23p4H73RGHA.4900@TK2MSFTNGP09.phx.gbl...
>> >> > Hello all,
>> >> >
>> >> > I have the following Outlook macro which has stopped working/is
>> >> > behaving
>> >> > erratically between machines. It's always behaved perfectly before.
>> >> >
>> >> > We have a client who sends 15 text files embedded in an email (not
>> >> > an
>> >> > attachment). We have to save them out as text files to our network.
>> >> >
>> >> > "If TypeOf obj Is Outlook.MailItem" seems to be the culprit.
>> >> > ExportMailToTxt is just bypassed.
>> >> >
>> >> > I have no idea why it would suddenly stop working. The only thing I
>> >> > can
>> >> > come up with is something in the client's emails are playing havoc
>> >> > with
>> >> > the macro.
>> >> >
>> >> > Can anyone give me a clue to this puzzle?
>> >> >
>> >> >
>> >> >
>> >> > 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 TypeOf obj Is Outlook.MailItem Then ' ///Item is not
>> >> > recognized
>> >> > as a MailItem?
>> >> > ExportMailToTxt obj, Chr$(96 + i), SALEDate ' ///This
>> >> > code
>> >> > is
>> >> > bypassed
>> >> > 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 Outlook.MailItem, _
>> >> > 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
>> >> > ExportMailToTxt = (Err.Number = 0)
>> >> > End Function
>> >> >
>> >> >
>> >> >
>> >>
>> >>
>> >>

>>
>>
>>



  Reply With Quote
Old 14-03-2006, 09:48 PM   #7
=?Utf-8?B?RXJpYyBMZWdhdWx0IFtNVlAgLSBPdXRsb29rXQ==
Guest
 
Posts: n/a
Default Re: Why did my macro suddenly stop working?

To be extra safe, change the "oMail As Outlook.MailItem" argument in the
ExportMailToTxt procedure to "oMail As Object".

--
Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Dale" wrote:

> Eric,
>
> It worked great on my machine. On the affected machine it gave a type
> mismach error. F8'ing thru it was going to execute the ExportMailToTxt
> function but apparently one of the items being passed was of the wrong type.
>
> Dale
>
>
> "Eric Legault [MVP - Outlook]" <elegaultZZZ@REMOVEZZZmvps.org> wrote in
> message news:A74F19E1-2405-4E55-B04E-468EEE577E88@microsoft.com...
> > You got me - I'm not really sure. I've actually never seen
> > Outlook.MailItem
> > used in an evaluative expression before, and I never use TypeOf with
> > Outlook
> > (no particular reason). I'm just more comfortable using Class or
> > MessageClass properties to evaluate objects. Does the code make a
> > difference
> > for you anyway?
> >
> > --
> > Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
> > Try Picture Attachments Wizard for Outlook:
> > http://www.collaborativeinnovations.ca
> > Blog: http://blogs.officezealot.com/legault/
> >
> >
> > "Dale" wrote:
> >
> >> Thanx for the reply Eric.
> >>
> >> What is the difference?
> >>
> >> Dale
> >>
> >> "Eric Legault [MVP - Outlook]" <elegaultZZZ@REMOVEZZZmvps.org> wrote in
> >> message news:AC110A88-C0B3-4C8F-884D-0B2C15C5FF6C@microsoft.com...
> >> > Change this:
> >> >
> >> > If TypeOf obj Is Outlook.MailItem Then
> >> >
> >> > to this:
> >> >
> >> > If obj.Class = olMail Then
> >> >
> >> > --
> >> > Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
> >> > Try Picture Attachments Wizard for Outlook:
> >> > http://www.collaborativeinnovations.ca
> >> > Blog: http://blogs.officezealot.com/legault/
> >> >
> >> >
> >> > "Dale" wrote:
> >> >
> >> >> Sorry, in rereading my post I shoud have said"
> >> >>
> >> >> We have a client who sends 15 emails. We have to save them out as
> >> >> text
> >> >> files to our network
> >> >>
> >> >>
> >> >> ..
> >> >>
> >> >> "Dale" <D-Man> wrote in message
> >> >> news:u%23p4H73RGHA.4900@TK2MSFTNGP09.phx.gbl...
> >> >> > Hello all,
> >> >> >
> >> >> > I have the following Outlook macro which has stopped working/is
> >> >> > behaving
> >> >> > erratically between machines. It's always behaved perfectly before.
> >> >> >
> >> >> > We have a client who sends 15 text files embedded in an email (not
> >> >> > an
> >> >> > attachment). We have to save them out as text files to our network.
> >> >> >
> >> >> > "If TypeOf obj Is Outlook.MailItem" seems to be the culprit.
> >> >> > ExportMailToTxt is just bypassed.
> >> >> >
> >> >> > I have no idea why it would suddenly stop working. The only thing I
> >> >> > can
> >> >> > come up with is something in the client's emails are playing havoc
> >> >> > with
> >> >> > the macro.
> >> >> >
> >> >> > Can anyone give me a clue to this puzzle?
> >> >> >
> >> >> >
> >> >> >
> >> >> > 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 TypeOf obj Is Outlook.MailItem Then ' ///Item is not
> >> >> > recognized
> >> >> > as a MailItem?
> >> >> > ExportMailToTxt obj, Chr$(96 + i), SALEDate ' ///This
> >> >> > code
> >> >> > is
> >> >> > bypassed
> >> >> > 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 Outlook.MailItem, _
> >> >> > 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
> >> >> > ExportMailToTxt = (Err.Number = 0)
> >> >> > End Function
> >> >> >
> >> >> >
> >> >> >
> >> >>
> >> >>
> >> >>
> >>
> >>
> >>

>
>
>

  Reply With Quote
Old 14-03-2006, 10:22 PM   #8
Dale
Guest
 
Posts: n/a
Default Re: Why did my macro suddenly stop working?

Sounds like a plan. Thanx (immensely) for the help.

BTW. I had some luck.

We updated the version of outlook to service pack 2 and wa-la. She flies!



"Eric Legault [MVP - Outlook]" <elegaultZZZ@REMOVEZZZmvps.org> wrote in
message news:9E333013-8A26-41FC-82B0-4D914E21A9F0@microsoft.com...
> To be extra safe, change the "oMail As Outlook.MailItem" argument in the
> ExportMailToTxt procedure to "oMail As Object".
>
> --
> Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
> Try Picture Attachments Wizard for Outlook:
> http://www.collaborativeinnovations.ca
> Blog: http://blogs.officezealot.com/legault/
>
>
> "Dale" wrote:
>
>> Eric,
>>
>> It worked great on my machine. On the affected machine it gave a type
>> mismach error. F8'ing thru it was going to execute the ExportMailToTxt
>> function but apparently one of the items being passed was of the wrong
>> type.
>>
>> Dale
>>
>>
>> "Eric Legault [MVP - Outlook]" <elegaultZZZ@REMOVEZZZmvps.org> wrote in
>> message news:A74F19E1-2405-4E55-B04E-468EEE577E88@microsoft.com...
>> > You got me - I'm not really sure. I've actually never seen
>> > Outlook.MailItem
>> > used in an evaluative expression before, and I never use TypeOf with
>> > Outlook
>> > (no particular reason). I'm just more comfortable using Class or
>> > MessageClass properties to evaluate objects. Does the code make a
>> > difference
>> > for you anyway?
>> >
>> > --
>> > Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
>> > Try Picture Attachments Wizard for Outlook:
>> > http://www.collaborativeinnovations.ca
>> > Blog: http://blogs.officezealot.com/legault/
>> >
>> >
>> > "Dale" wrote:
>> >
>> >> Thanx for the reply Eric.
>> >>
>> >> What is the difference?
>> >>
>> >> Dale
>> >>
>> >> "Eric Legault [MVP - Outlook]" <elegaultZZZ@REMOVEZZZmvps.org> wrote
>> >> in
>> >> message news:AC110A88-C0B3-4C8F-884D-0B2C15C5FF6C@microsoft.com...
>> >> > Change this:
>> >> >
>> >> > If TypeOf obj Is Outlook.MailItem Then
>> >> >
>> >> > to this:
>> >> >
>> >> > If obj.Class = olMail Then
>> >> >
>> >> > --
>> >> > Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
>> >> > Try Picture Attachments Wizard for Outlook:
>> >> > http://www.collaborativeinnovations.ca
>> >> > Blog: http://blogs.officezealot.com/legault/
>> >> >
>> >> >
>> >> > "Dale" wrote:
>> >> >
>> >> >> Sorry, in rereading my post I shoud have said"
>> >> >>
>> >> >> We have a client who sends 15 emails. We have to save them out as
>> >> >> text
>> >> >> files to our network
>> >> >>
>> >> >>
>> >> >> ..
>> >> >>
>> >> >> "Dale" <D-Man> wrote in message
>> >> >> news:u%23p4H73RGHA.4900@TK2MSFTNGP09.phx.gbl...
>> >> >> > Hello all,
>> >> >> >
>> >> >> > I have the following Outlook macro which has stopped working/is
>> >> >> > behaving
>> >> >> > erratically between machines. It's always behaved perfectly
>> >> >> > before.
>> >> >> >
>> >> >> > We have a client who sends 15 text files embedded in an email
>> >> >> > (not
>> >> >> > an
>> >> >> > attachment). We have to save them out as text files to our
>> >> >> > network.
>> >> >> >
>> >> >> > "If TypeOf obj Is Outlook.MailItem" seems to be the culprit.
>> >> >> > ExportMailToTxt is just bypassed.
>> >> >> >
>> >> >> > I have no idea why it would suddenly stop working. The only
>> >> >> > thing I
>> >> >> > can
>> >> >> > come up with is something in the client's emails are playing
>> >> >> > havoc
>> >> >> > with
>> >> >> > the macro.
>> >> >> >
>> >> >> > Can anyone give me a clue to this puzzle?
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> > 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 TypeOf obj Is Outlook.MailItem Then ' ///Item is not
>> >> >> > recognized
>> >> >> > as a MailItem?
>> >> >> > ExportMailToTxt obj, Chr$(96 + i), SALEDate ' ///This
>> >> >> > code
>> >> >> > is
>> >> >> > bypassed
>> >> >> > 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 Outlook.MailItem, _
>> >> >> > 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
>> >> >> > ExportMailToTxt = (Err.Number = 0)
>> >> >> > End Function
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >>
>> >> >>
>> >> >>
>> >>
>> >>
>> >>

>>
>>
>>



  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off