+ Reply to Thread
Results 1 to 4 of 4

User-defined type not defined when copying macro from one workbook to another

  1. #1
    Registered User
    Join Date
    01-02-2015
    Location
    Cambridge, UK
    MS-Off Ver
    2016
    Posts
    10

    User-defined type not defined when copying macro from one workbook to another

    Hi All,

    I have tried to copy over a macro from a different workbook that works absolutely fine, but when I pasted the code below into a module of my new workbook I get the error Compile error: User-defined type not defined on the line:
    Please Login or Register  to view this content.
    The macro prepares and populates a new email with specified text and part of the workbook pasted into the email. I don't understand why this worked perfectly well in the old workbook, but by transferring it into the new one it stops functioning? The full code is blow:

    Please Login or Register  to view this content.

  2. #2
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Re: User-defined type not defined when copying macro from one workbook to another

    Good afternoon Mogles

    You are missing a reference. In your original workbook, from the VBE go to Tools > References and note which ones are ticked.
    In your new workbook, do the same and you will probably find that one is missing. Find it, tick it, and you should be good to go.

    As you're doing something with e-mail it will probably be the Outlook Object Library (just a guess).

    HTH

    DominicB

  3. #3
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,159

    Re: User-defined type not defined when copying macro from one workbook to another

    You must select the appropriate reference (for Outlook) in "Tool \ References" (vba editor, alt+f11) in the new workbook.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: User-defined type not defined when copying macro from one workbook to another

    As has been said for that code you need a reference to the Outlook Object library, however if you changed to late-binding you wouldn't need the reference.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Compile Error: User-defined type not defined.
    By VAer in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-11-2017, 12:54 AM
  2. Replies: 4
    Last Post: 06-28-2016, 05:38 PM
  3. Replies: 2
    Last Post: 06-26-2016, 02:17 AM
  4. [SOLVED] Macro Button error ("user-defined type not defined")
    By brad.hodge in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-19-2016, 10:26 AM
  5. [SOLVED] User-defined type not defined on Copy to Clipboard Macro
    By vamosj in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-23-2015, 11:31 AM
  6. Compile error user defined type not defined
    By elloco240866_Alsdorf in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-31-2015, 02:26 AM
  7. VB Compile Error - User-defined type not defined
    By dbwiz in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-08-2010, 04:31 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1