Solved

Excel Email - compile error

Posted on 2013-05-16
5
277 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

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.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

622 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