Solved

Excel Email - compile error

Posted on 2013-05-16
5
269 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
Comment Utility
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 80

Expert Comment

by:byundt
Comment Utility
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
Comment Utility
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 80

Accepted Solution

by:
byundt earned 500 total points
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Sparklines have been introduced with Excel 2010 and are a useful tool for creating small in-cell charts, used for example in dashboards. Excel 2010 offers three different types of Sparklines: Line, Column and Win/Loss. What it does not offer is a…
Drop Down List with Unique/Distinct Values (enhancing the Combo-Box with a few steps and a little code) David miller (dlmille) Intro Have you ever created a data validation list from a database field or spreadsheet column (e.g., Zip Codes or Co…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
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…

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now