+ Reply to Thread
Results 1 to 8 of 8

Microsoft Scripting Library: Declaring file (variables/objects?): Is it an object or var.?

  1. #1
    Forum Contributor
    Join Date
    12-05-2015
    Location
    Akron, OH
    MS-Off Ver
    15.0
    Posts
    424

    Microsoft Scripting Library: Declaring file (variables/objects?): Is it an object or var.?

    How can I tell if something is an object or a variable in the Microsoft Scripting Runtime library? I ask b/c I believe that in order to use an object, you need to declare a new instance of an object; however, based on what I can compile below, it does not look like I need to declare a new instance of a file in order to use it.

    When I declare fil: Dim fil As Scripting.File...
    ...I do not need to declare a new instance of fil as I would with an object such as a collection or a file system object:
    Dim fso As Scripting.FileSystemObject
    Set fso = New Scripting.FileSystemObject

    But if a file isn't an object, why can I use a For - Each - Next syntax that I thought was reserved for looping over collections of objects?

    So I can write:

    Please Login or Register  to view this content.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Microsoft Scripting Library: Declaring file (variables/objects?): Is it an object or v

    Please Login or Register  to view this content.
    The Files method returns a collection of files.
    Last edited by shg; 01-04-2016 at 01:46 PM.
    Entia non sunt multiplicanda sine necessitate

  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,259

    Re: Microsoft Scripting Library: Declaring file (variables/objects?): Is it an object or v

    Hello joe31623,

    The For...Each...Next loop construct is used for arrays and Collections. The control variable can be either an Object of the same type as the array or collection or the control variable can be a Variant type.

    Hope that ansers your question.
    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
    Forum Contributor
    Join Date
    12-05-2015
    Location
    Akron, OH
    MS-Off Ver
    15.0
    Posts
    424

    Re: Microsoft Scripting Library: Declaring file (variables/objects?): Is it an object or v

    Leith,

    That helps with the For...Each...Next question. Thanks.

    shg,

    I probably wasn't clear about my question. The Files method is pretty straightforward.

    My question(s) relate(s) to whether or not a File datatype is an object or variable. If it's an object, why don't I need to create a new instance of it (like with Collections, FileSystemObjects, and User-defined Classes)? Or do you not always need to create a new instance of some objects before using them -- but if that is the case, why/when?

    Thanks Again...

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Microsoft Scripting Library: Declaring file (variables/objects?): Is it an object or v

    It's an object variable bound by the For Each loop. It is assigned sequentially to members of the collection.

    More or less the same reason you don't need to initialise i when you do

    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    12-05-2015
    Location
    Akron, OH
    MS-Off Ver
    15.0
    Posts
    424

    Re: Microsoft Scripting Library: Declaring file (variables/objects?): Is it an object or v

    Thanks for the quick responses!

  7. #7
    Forum Contributor
    Join Date
    12-05-2015
    Location
    Akron, OH
    MS-Off Ver
    15.0
    Posts
    424

    Re: Microsoft Scripting Library: Declaring file (variables/objects?): Is it an object or v

    To anyone else reading this, Microsoft has a good resource to learn more on this subject: https://technet.microsoft.com/en-us/.../ee198742.aspx

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Microsoft Scripting Library: Declaring file (variables/objects?): Is it an object or v

    You're welcome.

+ 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. macro to fix missing:microsoft outlook 14.0 object library
    By sujithy007 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-13-2021, 09:59 AM
  2. How can I reference Microsoft Outlook 15.0 Object Library?
    By rkjudy in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 04-11-2019, 06:25 AM
  3. Missing: Microsoft Powerpoint 15.0 Object Library
    By neetharao in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 11-28-2014, 12:59 PM
  4. how to keep checked Microsoft outlook 15.0 Object Library
    By Verbamore in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-09-2014, 08:45 PM
  5. Microsoft Outlook 14.0 vs 15.0 Object Library
    By Puff_N_Stuff in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-08-2014, 12:48 PM
  6. Microsoft ActiveX Data Objects 2.9 Library
    By timdecker in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-20-2014, 02:55 PM
  7. Microsoft HTML Object Library
    By akotronis in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-29-2013, 01:07 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