+ Reply to Thread
Results 1 to 6 of 6

Passing Array of Collections: Object or With Block not Set

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

    Passing Array of Collections: Object or With Block not Set

    When trying to pass an array of collections to another sub, I get the error: Object or with block not set. However, if I have already added an item to one of the collections, that collection works, but the other "empty" ones do not. Any idea why?

    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
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,560

    Re: Passing Array of Collections: Object or With Block not Set

    Public variable?
    Please Login or Register  to view this content.

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

    Re: Passing Array of Collections: Object or With Block not Set

    Is that what's causing the issue? Your code works. I made my variable public because I have some subroutines in UserForms and others in a standard module that I want to use the same list of files for. One sub collects the list of files, another gets all the file sizes, a third sorts it, a fourth calculates checksums, etc. Is there a way to a) make it work with a public variable or b) avoid using a public variable but use the same list of files in all my subs?

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

    Re: Passing Array of Collections: Object or With Block not Set

    No, you are trying to create an instance in Dim statement.
    If you want it public, no need to pass the variable to the next sub.
    Please Login or Register  to view this content.

  5. #5
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Passing Array of Collections: Object or With Block not Set

    One sub collects the list of files, another gets all the file sizes, a third sorts it, a fourth calculates checksums,
    So pass it as a parameter, your code needs refactoring

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

    Re: Passing Array of Collections: Object or With Block not Set

    jindon - Thank you. So, I'm gathering that simply ReDimming it doesn't initialize the member collections or something. It seems like the new keyword might do that. I'm actually not sure exactly what the new keyword does. Can explain it in this context?

    Kyle123 - I considered passing it as a parameter, but I don't have a good intuition about when things should be passed as parameters and when to use public variables. Do you have a rule of thumb for this? Also, what is refactoring?

+ 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. Passing information contained in {with...end with} block as UDF parameter
    By iamconfused in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-08-2013, 09:55 AM
  2. Collections within class module collections
    By AndyLitch in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-14-2013, 06:00 AM
  3. Collections, object, limits
    By kabarto in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-06-2012, 03:14 PM
  4. [SOLVED] Adding collections to collection Object error
    By stuart010 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 09-28-2012, 05:34 AM
  5. Passing Object Array to a Subroutine
    By Farmer in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-21-2011, 03:09 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