Solved

Excel Email - compile error

Posted on 2013-05-16
5
271 Views
Last Modified: 2013-05-17
I used the same code from another Excel Form (works perfectly) that is emailed with a command button, but on this form it errors out on the first line of code.

Compile Error: User-defined  type not defined.

It's probably something simple, but I can't find my error.

Any assistance or suggestions would be greatly appreciated.

Tosagua
OUTLOOK---PREMIUM-FREIGHT-FORM.xlsm
0
Comment
Question by:Tosagua
  • 2
  • 2
5 Comments
 
LVL 14

Expert Comment

by:comfortjeanius
ID: 39172910
Open the Macro and make sure this option check....


Tools > References > Check the checkbox in front of "Microsoft ActiveX Data Objects 2.5 Library"


Post Back
0
 
LVL 81

Expert Comment

by:byundt
ID: 39173753
What type of email software are you trying to use with the macro?

I've tried checking various references (including Microsoft ActiveX Data Objects 2.5 Library) and still get a compile error on this statement:
Dim mMail As Mail_Info

Although you may be able to fix the problem by checking the same references in this workbook as you did in the one you are copying from (as comfortjeanius was suggesting), the better solution is to use late-binding. In so doing, no references need to be checked and you won't get the "Missing Reference" error message when giving the workbook to a colleague.
0
 

Author Comment

by:Tosagua
ID: 39175144
byundt,

I agree that I have to get away from references in this form and the original.

But then I get confused

When you say late-binding, are you referring to "Dim mMail As Mail_Info", as the Object, and how do I do I dimension the related objects ?

At the end of the code, there seems to be a subroutine Creat_Word_Mail mMail, but I am unable to locate this anywhere.

Please advise.

Tosagua
0
 
LVL 81

Accepted Solution

by:
byundt earned 500 total points
ID: 39175435
With early-binding, you set a reference in the Tools...References menu item in the VBA Editor. You can then declare objects used by the library you added as a reference. So this statement:
Dim mMail As Mail_Info

Open in new window

appears to be an example of early-binding using the Mail_Info object from some email-capable software.

With late-binding, you don't need to set a reference. Instead, you tell VBA how to do it at run-time:
Dim appMail As Object
Set appMail = CreateObject("Application.Outlook")

Open in new window

You can now use Application.xxx methods, objects and properties from Outlook in your Excel VBA

The best guide on emailing from within Excel VBA is posted by Ron de Bruin at http://www.rondebruin.nl/win/section1.htm

Brad
0
 

Author Closing Comment

by:Tosagua
ID: 39175839
Brad,

Works great. Really appreciate the post by Ron de Bruin.
The code is greatly reduced and easier to use.

Thank you,

Tosagua
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directi…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

803 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