Page 1 of 2 12 LastLast
Results 1 to 15 of 24
  1. #1
    Miles R is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Mar 2019
    Posts
    280

    Intellisense with File Scripting and Shell Objects

    I am trying to write the correct code for folders and files in Access VBA. The code seems to work, but I don't think it is quite correct.


    The code is :
    Code:
    Dim fdrMainFolder As Folder
    Dim fdrSubFolder As Folder
    Dim fleFile As File
    Dim objFolder As Object
    Dim objFolderItem As Object
    
    Set gobjShell = New Shell
    Set gobjFSO = New FileSystemObject
    
    
    Set fdrMainFolder = gobjFSO.GetFolder(<path to main folder>)
    
    
    For Each fdrSubFolder In fdrMainFolder.SubFolders
    
        Set objFolder = gobjShell.Namespace(fdrSubFolder & "\")
                
        For Each fleFile In fdrSubFolder.Files
            Set objFolderItem = objFolder.ParseName(fleFile.Name)
    
    ......
    
    Next
    Intellisense works correctly for the objects defined as Folder and File, but not for those defined as Object.
    Should I be defining them in another way to get Intellisense to work?

    Also, it is not exactly clear to me why I need to get objFolder for a directory, since I already have fdrSubFolder set.
    Looking at the code through debug, fdrSubFolder has the full path name to the folder, but objFolder is just the name of the folder without the path. Clearly it is a different type of object to "Folder".

  2. #2
    Miles R is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Mar 2019
    Posts
    280
    Addendum to original post. I have managed to get Intellisense to work for objFolderItem, by defining it as FolderItem, but defining objFolder as Folder gives errors on objFolder.ParseName, so this is not correct.

  3. #3
    Miles R is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Mar 2019
    Posts
    280
    Further research has revealed that confusingly, there are several Classes named Folder which have different options.
    If I declare objFolder as Folder2, Intellisense works.
    Unclear exactly what this is all about at the moment.
    Attached Thumbnails Attached Thumbnails Folder.JPG  

  4. #4
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,879
    Couldn't you just use FSO alone? Recursive?
    What's your ultimate goal?
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  5. #5
    Miles R is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Mar 2019
    Posts
    280
    Thanks for the reply. My aim in this project is just to get some attributes from files in the subfolders. I don't need to do this recursively. I have done this successfully.
    However, my goal for this post was to get a better understanding as to how Scripting and Shell objects work and in particular, why are there several classes with the name Folder, doing slightly different things.
    It seems I need to use "Folder" to loop through subfolders and files, but "Folder2" to get attributes from files using GetDetailsof after using ParseName.
    Why are these methods not available in the first "Folder" class.
    It is quite difficult to find any answers for this on the Internet.

  6. #6
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    Have a look at my articles and example app: Extended File Properties (isladogs.co.uk)
    This allows you to obtain and store all the extended properties for:
    • an individual file
    • all files of a specified type in a selected folder
    • all files in a selected folder and (optionally) its subfolders

    All code is provided and can be used in your own apps.

    You can also see how it works in one of several videos linked in the article
    Hope that helps
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  7. #7
    Miles R is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Mar 2019
    Posts
    280
    Colin, Thanks for your reply. I will have a look at the video's in due course to understand things better.
    Actually, I don't have a problem with the extended file properties. I wrote an Excel program years ago which gets all extended file properties for files in any folder and all its subfolders recursively.
    Looking back at this code though, I realize I did not code it quite correctly with the right Dim's etc., so could not use Intellisense.
    Now I am trying to do things better and am trying to understand the Folder classes and why there are several of them.
    Perhaps a book on this might help if I can find one.

    p.s.

    I lot of effort went into this code and Access Databases I have created, so I hope they will still work when I migrate to 64 bit Office 365 on Windows 11.

  8. #8
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    My example app works in both 32-bit & 64-bit Access
    I'm also unclear why you need to do this recursively

    A very quick online search gave:

    Folder2
    Extends the Folder object to support offline folders
    Includes methods like Synchronize, which synchronizes all offline files in the folder


    Folder3
    Extends the Folder2 object, adding more advanced features
    Includes additional methods and properties to further manage and interact with Shell folders


    See
    https://vbaplanet.com/libshell32.php
    https://learn.microsoft.com/en-us/wi...folder2-object
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  9. #9
    Miles R is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Mar 2019
    Posts
    280
    Thanks Colin.
    Yes, in this particular code, I don't need recursive as I just wanted Fatt for one level down. In my Excel program however, it will drill down to every subdirectory. It takes quite a long time to get all 300+ attributes for all files in my Pictures or Music folders and subfolders.
    Glad to know this will still work on 64 Bit Access.
    One other thing I did notice years ago is that the Fatt offsets changed occasionally and I found the programs were not returning the correct attribute. I corrected this by running some code to extract the offsets for all attributes I am interested in (by name) when the programs are loaded. The offsets are then saved for later use in the program (won't work of course if they change the Fatt Name, but has not happened yet).

    Thanks for the info on Folder2 and Folder3. I need to do more research on this to understand better.
    Also, since there are two Classes named Folder, there must be some way to specify the second Folder class - the default seems to be the first, which is why GetDetailsOf does not work with Folder.
    This is why I chose Folder2.

  10. #10
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    I know what FAT means but no idea what FATT refers to
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  11. #11
    Miles R is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Mar 2019
    Posts
    280
    Ah,

    FATT or Fatt is short for File Attribute, i.e. its 300+ Metadata. Its a term I have been using for donkey's years. I thought it was in common usage, but maybe its something I invented when I was coding my programs.

  12. #12
    Miles R is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Mar 2019
    Posts
    280
    Coming back to my original question, after learning a bit more, I now would like to know how to refer to a specific object in the references to distinguish between those with the same name.
    So, Microsoft Scripting Runtime and Microsoft Shell Controls and Automation both have Classes (or is it objects?) call Folder.
    When I set something like DIM objFolder as Folder, it always refers to the one in Microsoft Scripting Runtime (I think).
    There must be some way to distinguish using the full name reference e.g.
    DIM msrObjFolder as "Microsoft Scripting Runtime".Folder
    DIM mscObjFolder as "Microsoft Shell Controls and Automation".Folder

    Maybe there is a way to set an alias for these as well.

    I have attempted to google this, but can't seem to phrase the question to get an answer. Perhaps I am not using the right terminology.

  13. #13
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,157
    Have you tried adjusting the order your references are set.
    I wonder if that would alter the default object?
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  14. #14
    Miles R is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Mar 2019
    Posts
    280
    Minty,

    I tried that, and yes it does change which is the default object.
    Still does not answer the question of how to fully reference the two Folder items as I use both.
    In the meantime, I will use Folder2 for the Parse and GetDetailsOf as this refers to the Microsoft Shell Controls and Automation Folder - I think.

  15. #15
    Miles R is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Mar 2019
    Posts
    280
    Found the answer to this.
    The Microsoft Shell Controls and Automation folder is declared as :-
    DIM <variable name> AS Shell32.Folder

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. IntelliSense (SQL Server Management Studio)
    By adnancanada in forum Queries
    Replies: 0
    Last Post: 08-04-2016, 11:42 PM
  2. Add more Intellisense to UDF in access
    By Perceptus in forum Programming
    Replies: 6
    Last Post: 09-17-2015, 03:12 PM
  3. Login Form and VBA scripting
    By data808 in forum Security
    Replies: 4
    Last Post: 02-27-2013, 12:01 AM
  4. Connect via ODBC and vb scripting or php
    By pkstormy in forum Code Repository
    Replies: 0
    Last Post: 08-28-2010, 08:41 PM
  5. intellisense not behaving
    By avianrand in forum Programming
    Replies: 3
    Last Post: 06-18-2010, 04:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums