2000 macro in 2003

  • Thread starter Thread starter Mike Miller
  • Start date Start date
M

Mike Miller

I have a macro I created in Outlook 2000 to send a
specific set of files to a specific address. It worked
fine in 2000, but I'm having a problem in 2003. When I
run the macro, it works fine and the files are sent as
expected; no errors, warnings or anything else. However,
the next time I open Outlook, I get a message saying
something had a serious failure the last time Outlook was
ran and it was disabled; when I look at Help, About, I see
that the VBA add-in has been disabled, and my macro won't
work any more. I can re-enable the macro, close Outlook,
restart, and the macro works fine again, but again, the
next time I open Outlook, I'll see the same error.

Here's the macro:
Sub SendAlmanac()

'create the email
Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.CreateItem(olMailItem)
Set myAttachments = myItem.Attachments

'add the Recipient
myItem.Recipients.Add "(e-mail address removed)"
myItem.Subject = "Subject"

'attach the files
myAttachments.Add "c:\file1"
<NOTE - this line contains the actual path to a file,
which I have verified is correct; there are about 10 files
in all>

'send the message
myItem.Send

End Sub
 
See if you don't get the problem if you use Application instead of
creating an Outlook.Application object, if you set all your objects =
Nothing at the end of your Sub and if you resolve the Recipient you
add to the email message. Also save the email message before you add
the attachment.
 
Ken,

Thanks for the suggestions. Unfortunately, I'm not that
familiar with VBA and I had some help putting that macro
together in the first place. Can you provide some more
specific instructions on how to make the changes you
suggest?

Also, I found a KB article that referenced a similar
problem, and it indicated Norton Antivirus "script
blocking" caused the problem. I disabled this and the
macro now works correctly (interesting this was never a
problem with Outlook 2000). I would prefer to keep script
blocking enabled - any thoughts on whether or not the
changes you suggested would allow the macro to run with
script blocking enabled?

Mike
 
I'd be interested in the KB number of that article on Norton script
blocking if you have it handy.

Norton's script blocking is a big problem for a lot of code. It can
cause Outlook to crash in COM addins and it seems to get worse the
later the Outlook version. Since there doesn't seem to be a way to
tell Norton to trust some programs I usually recommend that people
just disable any Norton script blocking. A nice idea but like lots of
the things they do it causes more problems than it solves in most
cases.

In this case I don't think the changes I suggested would make a
difference, since it's Norton that's at fault, but here is how I would
write that macro:

Sub SendAlmanac()
Dim myItem As Outlook.MailItem
Dim myAttachments As Outlook.Attachments

'create the email
Set myItem = Application.CreateItem(olMailItem)
Set myAttachments = myItem.Attachments

'add the Recipient
myItem.Recipients.Add "(e-mail address removed)"
myItem.Recipients(1).Resolve
If myItem.Recipients(1).Resolved Then
myItem.Subject = "Subject"
myItem.Save

'attach the files
myAttachments.Add "c:\file1"
' <NOTE - this line contains the actual path to a file,
' which I have verified is correct; there are about 10
' files in all>

'send the message
myItem.Send
Else
MsgBox "Failed to resolve " & myItem.Recipients(1).Name & _
" , " & myItem.Recipients(1).Address
End If

Set myItem = Nothing
Set myAttachments = Nothing
End Sub
 
Ken,

It's 303037. It doesn't say much other than if you have a
problem with a macro, it can be caused by Norton.

Thanks for the additional info on the macro. I'll make
those changes.

Thanks again.

Mike
 
Ken, Has this problem been resolved. This occurs with any VBA script and Symantec Script Blocking turned on.

Thanks,

Keith

----- Ken Slovak - [MVP - Outlook] wrote: -----

OK, thanks for that reference.
 
As usual Symantec refuses to acknowledge that there's a problem.

So you can turn off script blocking or you can try to use GetObject(,
"Outlook.Application") to avoid multiple uses of CreateObject. Of
course if all the code is in one place you can just set a global
object and reuse that. In cases like a COM addin DLL and a property
page OCX where you need to get an Outlook Application object in the
OCX to communicate with the DLL or for some other reason you can do
something like this:

Set oOL = GetObject(, "Outlook.Application")
If oOL Is Nothing Then
Set oOL = CreateObject("Outlook.Application")
End If

That would avoid the problem except in cases where GetObject fails,
which I have seen with some builds of Outlook 2002.

Other than that there's not much we can do except telling people to
avoid script blocking. Nice, huh?




Keith Campbell said:
Ken, Has this problem been resolved. This occurs with any VBA
script and Symantec Script Blocking turned on.
 
I'm not sure where you want that fix posted?

Just remember that if the GetObject call fails (which I've run into on
some builds of Outlook 2002) that the fallback to CreateObject will
return to the problems of NAV and other applications that use the
Office anti-virus API crashing Outlook.



Keith Campbell said:
Great job Ken. This worked perfectly. Can you post the fix in
"Microsoft VBA for Outlook becoming Disabled" message.
 
I am also having this problem with a macro that runs fine in Outloo
2002, but not Outlook 2003. I get the same "Outlook experience
serious error..." message that disables VBA. Unfortunately, turnin
script blocking off in Norton Antivirus did not resolve the problem.

Any ideas
 
You are using that horrid ExcelTips interface which doesn't put any of
the preceding thread in posts. Please do so manually, otherwise it
makes a thread very hard to follow.

Does it help if you shut down Norton completely? Does your macro use
CreateObject on an Outlook.Application or Word.Application object?
 
No, it does not help when I shut down Norton completely.
Yes, my macro contains this CreateObject statement:

Set myOlApp = CreateObject("Outlook.Application")

Bill




Does it help if you shut down Norton completely? Does your macro use
CreateObject on an Outlook.Application or Word.Application object?
 
UPDATE:

I was able to resolve this problem based on one of your prio
recommendations by using the following code:

Set myOlApp = GetObject(, "Outlook.Application")
If myOlApp Is Nothing Then
Set myOlApp = CreateObject("Outlook.Application")
End If

Everything works, even with Norton AntiVirus enabled and Scrip
Blocking on.

I can only imagine many, many people running into this same problem a
they upgrade to Office 2003. I spent a great deal of time searchin
the MS Knowledge Base, and I never found anything that addressed thi
problem. I would hope that this solution could get posted with MAN
keywords pointing to it!

Thanks for your help,
Bill





--

No, it does not help when I shut down Norton completely.
Yes, my macro contains this CreateObject statement:

Set myOlApp = CreateObject("Outlook.Application")

Bill
 
That solution was actually for a COM addin, not for a macro. In a
macro that runs in Outlook VBA you can use the intrinsic Application
object instead of instantiating a separate Outlook.Application object.
For example: Set oNS = Application.GetNameSpace("MAPI")

The GetObject workaround works most of the time but I've run into
cases where GetObject fails to return an Outlook.Application object
even when Outlook is running. Many of those cases seem to be updates
from Outlook 2002 to 2003 and sometimes can be fixed by running the
Office Repair option from the Add/Remove Programs application in the
Control Panel.

FWIW, there is a MS KB article about this problem using CreateObject
and the solution offered there is to disable Norton's script stopping.
That KB article dates from 2001, so that tells you how long the
problem has been around with Norton and their script stopper and you
can guess how many man hours they've put in to fix it since it still
exists.
 
Back
Top