Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Excel Email - compile error

Posted on 2013-05-16
5
Medium Priority
?
279 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 2000 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

[Webinar] Cloud Security

In this webinar you will learn:

-Why existing firewall and DMZ architectures are not suited for securing cloud applications
-How to make your enterprise “Cloud Ready”, and fix your aging DMZ architecture
-How to transform your enterprise and become a Cloud Enabler

Question has a verified solution.

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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

916 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