[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

What's missing from this Outlook 2003 macro?

Posted on 2009-02-11
8
Medium Priority
?
183 Views
Last Modified: 2012-05-06
I've copied code from pre-existing Outlook 2003 macros that work every time, but when I run this one, I get the message, Sub or Function not defined. What's missing, what wrong?
Public Sub Salesauto()
 
Dim olMail As Outlook.MailItem
Set olMail = Application.CreateItem(olMailItem)
Dim strMsg1 As String, strMsg2 As String
strMsg1 = "I am looking for introductions to business owners and senior managers you know who have at least three dedicated sales people in a B to B business with annual revenues of $8-50Million." & vbCrLf _
 
strMsg2 = "Chances are they have adopted some form of sales automation, or are thinking about it. For the majority of those who have adopted sales automation/CRM, they can relate to this invitation. I appreciate you passing this on to them. It's a registration form they can click on to sign up for my next seminar on March 9th in Newton." & vbCrLf _
& "If you have any questions please contact me directly. Thanks." & vbCrLf _
 
olMail.Body = strMsg1 & vbCrLf & strMsg2
olMail.Save
 
End Sub

Open in new window

0
Comment
Question by:walcottwhiz
  • 5
  • 3
8 Comments
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 23614517
You have an erroneous continuation character try:

Chris
Public Sub Salesauto()
 
Dim olMail As Outlook.MailItem
Set olMail = Application.CreateItem(olMailItem)
Dim strMsg1 As String, strMsg2 As String
strMsg1 = "I am looking for introductions to business owners and senior managers you know who have at least three dedicated sales people in a B to B business with annual revenues of $8-50Million." & vbCrLf
 
strMsg2 = "Chances are they have adopted some form of sales automation, or are thinking about it. For the majority of those who have adopted sales automation/CRM, they can relate to this invitation. I appreciate you passing this on to them. It's a registration form they can click on to sign up for my next seminar on March 9th in Newton." & vbCrLf _
& "If you have any questions please contact me directly. Thanks." & vbCrLf
 
olMail.Body = strMsg1 & vbCrLf & strMsg2
olMail.Save
 
End Sub

Open in new window

0
 

Author Comment

by:walcottwhiz
ID: 23614768
Chris,
I'm not sure what you mean here other than removing the underscore at the end of strMsg1. What am I not understanding? When I pasted your code in, I got the same message. What else can I try?
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 23614818
How are you calling the macro?

Chris
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 23614856
Note I thought I was being clever as the only thing I could see was the underscore ... however this wasn't it.  I can run the macro fine and it works, which is as I expect from the code so the next most likely factor is the method of calling hence the question.

Chris
0
 

Author Comment

by:walcottwhiz
ID: 23616544
This is weird. I have several different macros, half of which stand alone as single branches under the Modules tree, and the other half are collected together under one branch. When I added the original script to the collections of others (calling it differently), both the original script and the copied one ran perfectly. But when I deleted the macro from the collection, the original macro wouldn't run. So I copied the original script back under the single branch and added it to itself (starting a new collection) calling it a different name, and now they both run. Can you would please explain how and why this is, thanks.
0
 
LVL 59

Assisted Solution

by:Chris Bottomley
Chris Bottomley earned 2000 total points
ID: 23616715
Most likely it is down to a definition in your module but that should be the same wherever it is located.  The 'concern' is that in outlook it prefixes it's constants with ol.  olMail is in fact an outlook constant so you are over-writing that definition.

See how it works if you replace olmail in your definition with olkMail.

Chris
Public Sub Salesauto()
 
Dim olkMail As Outlook.MailItem
Set olMail = Application.CreateItem(olMailItem)
Dim strMsg1 As String, strMsg2 As String
strMsg1 = "I am looking for introductions to business owners and senior managers you know who have at least three dedicated sales people in a B to B business with annual revenues of $8-50Million." & vbCrLf
 
strMsg2 = "Chances are they have adopted some form of sales automation, or are thinking about it. For the majority of those who have adopted sales automation/CRM, they can relate to this invitation. I appreciate you passing this on to them. It's a registration form they can click on to sign up for my next seminar on March 9th in Newton." & vbCrLf _
& "If you have any questions please contact me directly. Thanks." & vbCrLf
 
olkMail.Body = strMsg1 & vbCrLf & strMsg2
olkMail.Save
 
End Sub

Open in new window

0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 23616725
MIssed one!
Public Sub Salesauto()
 
Dim olkMail As Outlook.MailItem
Set olkMail = Application.CreateItem(olMailItem)
Dim strMsg1 As String, strMsg2 As String
strMsg1 = "I am looking for introductions to business owners and senior managers you know who have at least three dedicated sales people in a B to B business with annual revenues of $8-50Million." & vbCrLf
 
strMsg2 = "Chances are they have adopted some form of sales automation, or are thinking about it. For the majority of those who have adopted sales automation/CRM, they can relate to this invitation. I appreciate you passing this on to them. It's a registration form they can click on to sign up for my next seminar on March 9th in Newton." & vbCrLf _
& "If you have any questions please contact me directly. Thanks." & vbCrLf
 
olkMail.Body = strMsg1 & vbCrLf & strMsg2
olkMail.Save
 
End Sub

Open in new window

0
 

Accepted Solution

by:
walcottwhiz earned 0 total points
ID: 23617424
It must be the way I'm creating a new module. All I'm doing is right clicking on the Module folder and choosing Insert new module. When I did that and copied in your macro, the same thing error message occured again.
0

Featured Post

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to import Lotus Notes Contacts into Outlook 2016, 2013, 2010 and 2007 etc. with a few manual steps. You can easily export and migrate Lotus Notes contacts into Microsoft Outlook without having to use any third party tools.
Mailbox Corruption is a nightmare every Exchange DBA wishes he never has. Recovering from it can be super-hectic if not entirely futile. And though techniques like the New-MailboxRepairRequest cmdlet have been designed to help with fixing minor corr…
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question