+ Reply to Thread
Results 1 to 9 of 9

Outlook VBA, how to add reference library ["User defined type not defined" ERROR]

  1. #1
    Registered User
    Join Date
    07-16-2014
    Location
    Seattle, WA
    MS-Off Ver
    Office 365
    Posts
    67

    Outlook VBA, how to add reference library ["User defined type not defined" ERROR]

    I'm trying to use a template in visual basic to ask for user input, then lookup that value in an excel spreadsheet, and enter the corresponding value into the template.
    I am receiving th error - "User defined type not defined" and the Dim x As Range line is highlighted.
    I have a feeling it is because Outlook VBA doesn't have access to the excel Range library.
    I've tried to go to tools -> references but there is not option for that in VBA, can anyone show me how to do it programatically?

    Please Login or Register  to view this content.
    Last edited by kelseygueldalewis; 08-23-2017 at 08:06 AM.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Outlook VBA, how to add reference library ["User defined type not defined" ERROR]

    There should be an option in References that looks like

    Microsoft Excel 15.0 Object Library

    It is possible to code this using late binding without the reference if you prefer. But that does detract from readability of the code because you cannot use any of the Excel object types, like Range and Workbook. You must declare them as Object.

    You must also create an Excel application object in your code, rather than starting right in to use Excel code. Something like this, but I haven't tested it because it is dependent on your environment and files.

    Please Login or Register  to view this content.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    07-16-2014
    Location
    Seattle, WA
    MS-Off Ver
    Office 365
    Posts
    67

    Re: Outlook VBA, how to add reference library ["User defined type not defined" ERROR]

    Thanks Jeff!

    Late Binding solved the problem of the orginal error - now I am receiving one at the VLOOKUP part. I changed it to include ExcelApp, but it's throwing a type mismatch error. I'm not sure how to debug the range (x) to see if it actually exists - I know that the t variable is fine. Any ideas?

    Please Login or Register  to view this content.

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Outlook VBA, how to add reference library ["User defined type not defined" ERROR]

    I have never used VLOOKUP (or any other worksheet functions) in a late binding situation. It may not be able to resolve an Object type when Excel is expecting a Range. If I find anything out I'll come back.

    Alternative is to set the reference. Are you sure Excel is not in the list?

  5. #5
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Outlook VBA, how to add reference library ["User defined type not defined" ERROR]

    Hi,

    A Type Mismatch error would suggest that VLookup is returning something that cannot be coerced to a Long value- either an error value or a text value most likely.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Outlook VBA, how to add reference library ["User defined type not defined" ERROR]

    Hello kelseygueldalewis,

    The code below should be copied and pasted into a new VBA module in an Excel Workbook. One of the macro listed can then be added to your Word Document macros to load the Excel type library giving you full access to the objects and methods in Excel.

    Add this code to an Excel Workbook
    Run the macro "List_References". This will provide you with the GUID, major, and minor version numbers needed for the macro "Load_Reference" in your Word Document.
    Please Login or Register  to view this content.
    Add this macro to your Word Document
    Please Login or Register  to view this content.
    Example of calling the macro in Word
    In your Word Document before you make any reference to Excel or it's objects, call this macro with the information you obtained about Excel. For example, in Windows 10 the call looks like this...
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  7. #7
    Registered User
    Join Date
    07-16-2014
    Location
    Seattle, WA
    MS-Off Ver
    Office 365
    Posts
    67

    Re: Outlook VBA, how to add reference library ["User defined type not defined" ERROR]

    Thank you everyone for your responses, I asked the question in trying to help another user solve a problem - so as far as they described it I ended up just using an if statement since it was pretty basic. If it gets more complicated I may be back again but I will consider this one solved for now. Here is my final code for reference.

    Please Login or Register  to view this content.

  8. #8
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Outlook VBA, how to add reference library ["User defined type not defined" ERROR]

    There's quite a large problem with that, namely
    Please Login or Register  to view this content.
    is true for any number (in fact pretty much any value other than Null). You need two separate tests
    Please Login or Register  to view this content.
    The former code has two possible paths
    1. If 2 < t then the evaluation of 2 < t < 5 is true because 2 < t = True, which coerces to -1 which is less than 5.
    2. If 2 >= t, then it's true because False coerces to 0 which is also less than 5.
    Last edited by xlnitwit; 08-23-2017 at 08:15 AM.

  9. #9
    Registered User
    Join Date
    07-16-2014
    Location
    Seattle, WA
    MS-Off Ver
    Office 365
    Posts
    67

    Re: Outlook VBA, how to add reference library ["User defined type not defined" ERROR]

    @xlnitwit thanks! I will update accordingly

+ 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] 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
  2. Replies: 4
    Last Post: 11-13-2015, 09:03 PM
  3. "User-defined type not defined"
    By jirakst in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-04-2015, 11:13 AM
  4. Error message: "Compile error. User-defined type not defined"
    By freckles81 in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 06-13-2012, 09:37 AM
  5. Error message: "Compile error. User-defined type not defined"
    By lottesfog in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-25-2007, 06:38 PM
  6. "User-defined type not defined" error when trying to send e-mail
    By SupperDuck in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-02-2006, 02:40 AM
  7. "User-defined type not defined" message in Excel
    By RW1946 in forum Excel General
    Replies: 0
    Last Post: 08-31-2005, 08:05 AM

Tags for this Thread

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