Email macro in a template

B

Bonnie

I have created a template that contains a macro that will save the
document and then email it to 3 people. This all works fine from my xp
prof system running office 2003. However, from a win 98se system
running office 97, it sends an email with no attachment. This is all
brand new to me and I've been learning as I go and have no idea what is
wrong. Can anyone help me? Here is the code:

Sub SendDocumentAsAttachment()

Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem

On Error Resume Next



ActiveDocument.SaveAs


Set oOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If

Set oItem = oOutlookApp.CreateItem(olMailItem)

With oItem
.To = "(e-mail address removed); (e-mail address removed);
(e-mail address removed);"
.Subject = "New Maintenance Work Order"
'Add the document as an attachment, you can use the .displayname
property
'to set the description that's used in the message
.Attachments.Add Source:=ActiveDocument.FullName, Type:=olByValue,
_
DisplayName:="Document as attachment"
.Send
End With

If bStarted Then
oOutlookApp.Quit
End If

Set oItem = Nothing
Set oOutlookApp = Nothing

End Sub
 
M

Malcolm Smith

*From:* "Bonnie" <[email protected]>
*Date:* 10 Jan 2007 07:34:41 -0800

I have created a template that contains a macro that will save the
document and then email it to 3 people. This all works fine from my xp
prof system running office 2003. However, from a win 98se system
running office 97, it sends an email with no attachment. This is all
brand new to me and I've been learning as I go and have no idea what is
wrong. Can anyone help me? Here is the code:

Sub SendDocumentAsAttachment()

Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem

On Error Resume Next



ActiveDocument.SaveAs


Set oOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If

Set oItem = oOutlookApp.CreateItem(olMailItem)

With oItem
.To = "(e-mail address removed); (e-mail address removed);
(e-mail address removed);"
.Subject = "New Maintenance Work Order"
'Add the document as an attachment, you can use the .displayname
property
'to set the description that's used in the message
.Attachments.Add Source:=ActiveDocument.FullName, Type:=olByValue,
_
DisplayName:="Document as attachment"
.Send
End With

If bStarted Then
oOutlookApp.Quit
End If

Set oItem = Nothing
Set oOutlookApp = Nothing

End Sub


If you remove the On Error Resume Next statement (or rem it out) then see
what happens then.

- Malc
 
B

Bonnie

Malcolm said:
If you remove the On Error Resume Next statement (or rem it out) then see
what happens then.

- Malc

I removed that statement and now I get an error when the macro runs on
the 98 system (it still works fine on xp with office 2003):

cannot run activex document

I feel stupid.........
 
M

Malcolm Smith

*From:* "Bonnie" <[email protected]>
*Date:* 10 Jan 2007 08:02:13 -0800




I removed that statement and now I get an error when the macro runs on
the 98 system (it still works fine on xp with office 2003):

cannot run activex document

I feel stupid.........


On which line is the error, please?

- Malc
 
B

Bonnie

Malcolm said:
On which line is the error, please?

- Malc


Ok-here's the whole scenario:

On a 98se system with office 97---you open a new document based on a
template on the server. In the template is this macro I stated above.
When it executes we get this message:

Could Not open macro storage. When you click OK, you get this message

Compile Error--Can't find project or library.

This is the line that is highlighted

Dim oOutlookApp As Outlook.Application

In my reading on this site and others, I'm thinking it has something to
do with the references and the version differences. Thanks so much for
your help! I'm so busy here and there's no one else that knows
anything about it.
 
D

Doug Robbins - Word MVP

You will need to set a reference under Tools>References in the Visual Basic
Editor to the Microsoft Outlook Object Library that is available on that
system.

Under Office 2003, the reference would be to the Microsoft Outlook 11.0
Object Library. Under Office 97, it will be to the Microsoft Outlook 9.0
Object Library.
--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
B

Bonnie

Thankyou--I have changed that before, but when an office 2003 system
opens it, it automatically changed it back to 11.0. So I have made two
different templates, one for 98 systems and one for xp. Thanks for all
your help.
 
B

Bonnie

Thankyou--I have changed that before, but when an office 2003 system
opens it, it automatically changed it back to 11.0. So I have made two
different templates, one for 98 systems and one for xp. Thanks for all
your help.
 
M

Malcolm Smith

*From:* "Bonnie" <[email protected]>
*Date:* 11 Jan 2007 05:59:26 -0800

Thankyou--I have changed that before, but when an office 2003 system
opens it, it automatically changed it back to 11.0. So I have made two
different templates, one for 98 systems and one for xp. Thanks for all
your help.



What you could do rather than to maintain TWO templates is to removed the
Outlook references and then to have the variable types set to Object and
then create them by LATE BINDING.

Then the code will work for either version of Outlook.

Shout if you need more information.

- Malc
 

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