Solved

Excel Email - compile error

Posted on 2013-05-16
5
273 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
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.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

830 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