+ Reply to Thread
Results 1 to 11 of 11

Why will this macro only run from PERSONAL.xlsb?

  1. #1
    Forum Contributor terrypin's Avatar
    Join Date
    01-06-2010
    Location
    East Grinstead, UK
    MS-Off Ver
    MS Office 365
    Posts
    548

    Why will this macro only run from PERSONAL.xlsb?

    I finally got this macro working. With the full filename of a JPG image on the clipboard, it insers that as a picture in the active worksheet:

    Please Login or Register  to view this content.
    HOWEVER, it will only work if I place it in Personal.xlsb. If I put it in the worksheet in which I want to work, TrackData-New.xlsm, I get this error: "Compile error: User-defined type not defined".

    I did observe the obscure instruction I had found, namely that for this to work you must "Have at least one UserForm in your project".

    ClipMacroNotWorking.jpg

    Anyone know the reason for this failure and how to fix please?
    Terry, East Grinstead, UK
    Excel 365, Win 10 Pro, i7 PC, 4.0 GHz

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,379

    Re: Why will this macro only run from PERSONAL.xlsb?

    User forms are not the same things as user-defined data types, so I'm not sure why the user form should be a part of this. User-defined data types are defined using the Type statement (https://msdn.microsoft.com/en-us/vba...type-statement ). You use the Dim statement to define a variable as a built in or user-defined data type (https://msdn.microsoft.com/en-us/vba.../dim-statement shows a list of built in data types).

    Your insertpicture procedure dim's a variable MyData as a DataObject type -- which does not look like one of VBA's built in data types, so I think this is what it is looking for when it says there is no user-defined type defined. I am guessing that your personal.xlsb has a Type statement somewhere that defines what a DataObject type contains. When the code is contained in the same module as the Type statement that defines this user-defined type, the code works just fine.

    The first solution I see is to make sure that you copy the Type definition into the desired VBA project module along with the Sub code. The other possibility is to restructure the code so that it does not use the user-defined type.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  3. #3
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,292

    Re: Why will this macro only run from PERSONAL.xlsb?

    Did you make a reference to Microsoft Forms 2.0 Object Library in the workbook you're working in ?
    Also not necessary to declare DataObject.
    Please Login or Register  to view this content.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  4. #4
    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: Why will this macro only run from PERSONAL.xlsb?

    You can skip the reference and late bind
    Please Login or Register  to view this content.
    You should also be aware that the dataobject is a little buggy in versions of Windows from 8 onwards.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  5. #5
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,292

    Re: Why will this macro only run from PERSONAL.xlsb?

    Or even.
    Please Login or Register  to view this content.

  6. #6
    Forum Contributor terrypin's Avatar
    Join Date
    01-06-2010
    Location
    East Grinstead, UK
    MS-Off Ver
    MS Office 365
    Posts
    548

    Re: Why will this macro only run from PERSONAL.xlsb?

    Quote Originally Posted by bakerman2 View Post
    Did you make a reference to Microsoft Forms 2.0 Object Library in the workbook you're working in ?
    Also not necessary to declare DataObject.
    Please Login or Register  to view this content.
    Thanks, a breakthrough! No, I had not made "...a reference to Microsoft Forms 2.0 Object Library...". (And have no idea why I would need to. Or why it isn't set as a default if stuff needs it. I need to start prefacing my questions with 'VBA novice'.) But having now done so 'my' macro now works in the target worksheet as well as Personal.xlsb.

    However yours gives an error:

    Please Login or Register  to view this content.
    Having been asked recently not to edit posts under discussion, I'm now replying to posts individually. So maybe the later posts from you and xlnitwit will explain that.
    Last edited by AliGW; 02-09-2018 at 06:54 AM.

  7. #7
    Forum Contributor terrypin's Avatar
    Join Date
    01-06-2010
    Location
    East Grinstead, UK
    MS-Off Ver
    MS Office 365
    Posts
    548

    Re: Why will this macro only run from PERSONAL.xlsb?

    Quote Originally Posted by xlnitwit View Post
    You can skip the reference and late bind
    Please Login or Register  to view this content.
    You should also be aware that the dataobject is a little buggy in versions of Windows from 8 onwards.
    Thanks, no idea why but that works a treat!

    Please Login or Register  to view this content.

  8. #8
    Forum Contributor terrypin's Avatar
    Join Date
    01-06-2010
    Location
    East Grinstead, UK
    MS-Off Ver
    MS Office 365
    Posts
    548

    Re: Why will this macro only run from PERSONAL.xlsb?

    Quote Originally Posted by bakerman2 View Post
    Or even.
    Please Login or Register  to view this content.
    Yes, that works sweetly too , many thanks!

    Please Login or Register  to view this content.

  9. #9
    Forum Contributor terrypin's Avatar
    Join Date
    01-06-2010
    Location
    East Grinstead, UK
    MS-Off Ver
    MS Office 365
    Posts
    548

    Re: Why will this macro only run from PERSONAL.xlsb?

    Thanks MrShorty.

    As a VBA novice (and likely to remain one) I'm afraid most of that is over my head. And the more I dug into it (early binding, late binding, type libraries, application references, object declarations, etc) the more lost I became.

    But I latched onto your suspicion: "I am guessing that your personal.xlsb has a Type statement somewhere that defines what a DataObject type contains." As you'll have seen from my last few replies, I have it working now (in any of three forms). But I'm still curious as to why it worked before in PERSONAL.xlsb, before I had seen bakerman2's point about a "reference to Microsoft Forms 2.0 Object Library". So I've just searched the PERSONAL 'project' using the target 'Type'. From its scores of macros, only this one below gave a hit. (Can't remember its source.) Do you think this could be the answer to the puzzle?

    Please Login or Register  to view this content.

  10. #10
    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: Why will this macro only run from PERSONAL.xlsb?

    You must, at some point, have added a reference to the MSForms library. Adding a userform would automatically have done that for you.

  11. #11
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,292

    Re: Why will this macro only run from PERSONAL.xlsb?

    Most important thing is that you got it all working smoothly.
    Thanks for rep+.

+ 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] to use variables from macro of personal.xlsb
    By sandordan_01 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 12-21-2017, 05:46 AM
  2. [SOLVED] Personal.XLSB macro pasting into Personal.XLSB
    By davepoth in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-11-2015, 07:40 PM
  3. Running a Personal.XLSB Macro From Within Another Personal.XLSB Macro
    By js0873 in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 06-23-2015, 09:58 AM
  4. Replies: 0
    Last Post: 01-15-2015, 05:53 AM
  5. [SOLVED] Personal.xlsb Macro Naming Format
    By freybe06 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-23-2014, 04:20 PM
  6. cannot run macro if personal.xlsb is hidden
    By illusionek in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-07-2014, 08:16 AM
  7. Add procedure to PERSONAL.XLSB with a macro from another workbook.
    By dimattia in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-31-2013, 10:21 AM

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