+ Reply to Thread
Results 1 to 8 of 8

Error: Method or Data Member Not Found

  1. #1
    Valued Forum Contributor
    Join Date
    08-06-2013
    Location
    Detroit, Michigan
    MS-Off Ver
    Excel 2013
    Posts
    671

    Error: Method or Data Member Not Found

    I am trying to run the following code from https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx
    However, when I try to run it, I get a message saying "Compile Error: Method or Data Member not Found"

    I have added the Microsoft Internet Tools and Microsoft Shell Control and Automation references to my workbook, like the site said. Any help with this would be appreciated.

    Please Login or Register  to view this content.
    1. Include a sample workbook with an example of the result you want
    2. Use [CODE] and [FORMULA] wrappers for your VBA code or excel formulas
    3. If your question has been answered, mark the thread as SOLVED and click on the "Add Rep" star to thank whoever helped you.

  2. #2
    Valued Forum Contributor
    Join Date
    08-06-2013
    Location
    Detroit, Michigan
    MS-Off Ver
    Excel 2013
    Posts
    671

    Re: Error: Method or Data Member Not Found

    Well, as Murphy's law would have it, I have discovered the answer immediately after posting. Changing "Dim objFolder As Folder" to "Dim objFolder As Folder2" fixed it.

  3. #3
    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: Error: Method or Data Member Not Found

    Hello k64,

    You need to be careful with the Shell and typing the variables. You need to define constant values as Constants whether they are strings or numbers.

    This works...
    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!)

  4. #4
    Valued Forum Contributor
    Join Date
    08-06-2013
    Location
    Detroit, Michigan
    MS-Off Ver
    Excel 2013
    Posts
    671

    Re: Error: Method or Data Member Not Found

    Thank you Leith, was it the constants that were causing the issue, or the early binding of the objects?

  5. #5
    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: Error: Method or Data Member Not Found

    Hello k64,

    Working with the Shell can be a bit finicky. The Namespace property is usually where people get tripped up. It will only accept constant values or a variant data type.

    Examples:
    Please Login or Register  to view this content.
    Also, I generally don't make a habit of loading libraries in my code since most of what I do is redistributed. Keeping objects generic avoids the pitfall of declaring an object as the wrong class. Early binding is nice because of the intellisense. As you discovered with FolderItems2 and FolderItems3. FolderItems3 is returned only for items of a folder as a collection and as individual items.

  6. #6
    Valued Forum Contributor
    Join Date
    08-06-2013
    Location
    Detroit, Michigan
    MS-Off Ver
    Excel 2013
    Posts
    671

    Re: Error: Method or Data Member Not Found

    Thank you Leith Ross,

    That's good info to have. So, do you just dim all objects as Object and then set = CreateObject? I'm still a bit confused about folderItems, FolderItems2, and FolderItems3. If you have a Folder and take its Items property, how do you know which of those it will be?

  7. #7
    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: Error: Method or Data Member Not Found

    Hello k64,

    Generally, I dimension my objects using the generic object type Object because you don't have to know ahead of time which object type you are dealing with (late binding). As you have found out using early binding with Shell can be problematic.

    You can easily discover the object type in VBA by using the TypeName function. This works for objects and all other variable types.

    Examples
    Please Login or Register  to view this content.
    Once you know the object type, you can then use the object browser in VBA to look at the properties, methods, and other objects associated with the variable type.

  8. #8
    Valued Forum Contributor
    Join Date
    08-06-2013
    Location
    Detroit, Michigan
    MS-Off Ver
    Excel 2013
    Posts
    671

    Re: Error: Method or Data Member Not Found

    Thank you Leith Ross. I never knew about the TypeName function. That will help a lot!

+ 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. Compile Error Method or data member not found
    By ixelister in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-23-2014, 03:39 PM
  2. [SOLVED] error: Method or Data Member not found
    By CRIMEDOG in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-26-2013, 11:01 AM
  3. [SOLVED] Compile error: Method or data member not found.
    By ndtsteve in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-10-2012, 11:31 AM
  4. Compile Error: Method of data member not found (VBA)
    By vbatech in forum Excel Programming / VBA / Macros
    Replies: 22
    Last Post: 03-14-2012, 05:37 PM
  5. Compile Error Method or data member not found
    By ExcelMonkey in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-04-2005, 06:05 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