+ Reply to Thread
Results 1 to 15 of 15

User-defined type not defined

  1. #1
    Forum Contributor
    Join Date
    07-07-2014
    Location
    Nottingham
    MS-Off Ver
    Office 2016
    Posts
    355

    User-defined type not defined

    I have added a macro to attach a highlighted section of excel to an email as a pdf.

    This was working perfectly in my test workbook. When I tried to add the same macro to my working workbook i got a "Compile Error: User-defined type not defined".

    I thought it might have been just on my live workbook, but the attached gets the same issue.

    What am I not seeing?
    Attached Files Attached Files

  2. #2
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,913

    Re: User-defined type not defined

    You haven't set a reference to the Outlook object library in that workbook.
    Rory

  3. #3
    Forum Contributor
    Join Date
    07-07-2014
    Location
    Nottingham
    MS-Off Ver
    Office 2016
    Posts
    355

    Re: User-defined type not defined

    You lost me at "Set a reference". Could you let me know what I need to add/alter to get it to work?

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,853

    Re: User-defined type not defined

    Developer tab > VBA Editor > Tools > References ...

    Find the correct object on the list and tick it.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  5. #5
    Forum Contributor
    Join Date
    07-07-2014
    Location
    Nottingham
    MS-Off Ver
    Office 2016
    Posts
    355

    Re: User-defined type not defined

    Hello again Ali

    I did that when I originally set up the macro.

    AND I have just seen the reason it didn't work, I allocated the MS Office, not the MS Outlook reference, but I do not see how/why it would work in the first instance, then not.
    Attached Images Attached Images

  6. #6
    Forum Contributor
    Join Date
    07-07-2014
    Location
    Nottingham
    MS-Off Ver
    Office 2016
    Posts
    355

    Re: User-defined type not defined

    I am having a further issue with the same macro.

    The end of the script should delete the temp PDF. I am happy to remove this bit of code as ideally I want the PDFs to be saved as well as emailed, so not deleting is a bit of a blessing in disguise.

    But, for my own sanity, can someone explain why the Permission Denied error appears?
    Attached Images Attached Images

  7. #7
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,853

    Re: User-defined type not defined

    but I do not see how/why it would work in the first instance, then not.
    Because there are separate objects for each of the Office components (Word, Excel, Outlook, etc.). I learnt this when I was merging data from Excel into Word via VBA.

  8. #8
    Forum Contributor
    Join Date
    07-07-2014
    Location
    Nottingham
    MS-Off Ver
    Office 2016
    Posts
    355

    Re: User-defined type not defined

    Quote Originally Posted by AliGW View Post
    Because there are separate objects for each of the Office components
    Yep, I fully get that now. But I cannot fathom why it would work initially with "Office" applied, but then 'break', but work when "Outlook" was added.

    but it is working, which is a god-send.

    Thank you.

  9. #9
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,853

    Re: User-defined type not defined

    I don't know the answer to that, but if the object wasn't selected, then the call on it would fail. Something else may have been the cause.

  10. #10
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,913

    Re: User-defined type not defined

    You said you moved the code from one workbook to another. The reference is stored with the workbook, not the code, so I suspect that initially you had correctly added the outlook reference to your test workbook. The Office reference is selected by default.

  11. #11
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: User-defined type not defined

    Your code is using late binding, so change Dim statement
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    So that no need to set the reference.

  12. #12
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,913

    Re: User-defined type not defined

    Quote Originally Posted by jindon View Post
    Your code is using late binding, so change Dim statement
    Please Login or Register  to view this content.
    That is early binding, since the variables are declared as specific types, not Object. Your suggested changes would make it late binding. (using CreateObject does not determine the binding context)

  13. #13
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: User-defined type not defined

    You need to read the code in the workbook uploaded.
    Please Login or Register  to view this content.

  14. #14
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,913

    Re: User-defined type not defined

    I've read the code. It contains this:

    Please Login or Register  to view this content.
    and that is early binding. As I said, using CreateObject does not determine binding context; only the variable declaration does that.

  15. #15
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: User-defined type not defined

    But it is not actually early binding unless set the reference.

    Anyway it should work.

+ 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. Userform - VBA code compile error: User-defined type not defined
    By rayhee1985 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-14-2020, 11:03 AM
  2. [SOLVED] getting user defined type not defined when trying to add a reference manually
    By dmcgov in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-24-2019, 10:48 AM
  3. User-defined type not defined when copying macro from one workbook to another
    By Mogles in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-01-2018, 08:08 AM
  4. Replies: 4
    Last Post: 06-28-2016, 05:38 PM
  5. Replies: 2
    Last Post: 06-26-2016, 02:17 AM
  6. [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
  7. Compile error: user defined type not defined
    By duhigs in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-23-2014, 07:51 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