+ Reply to Thread
Results 1 to 6 of 6

VBA Code for specific subfolder

  1. #1
    Registered User
    Join Date
    02-24-2022
    Location
    Romania
    MS-Off Ver
    360
    Posts
    4

    Post VBA Code for specific subfolder

    Capture.PNG


    Hello everyone,

    I am new to this wonderful forum and equally new to VBA.

    I have the following situation:
    the main folder ( Projects) which contains a number of 5 subfolders ( named Projects 1, Projects 2 and so on) each of these subfolders has 4 more subfolders named the same (Vendors, Planning, Schedule, Team).

    I'm interested in opening each individual Project (Projects 1, Projects 2 and so on) and opening only the folder named Schedule.
    I want to tell me in a message or display in an excel table if any files were added in the last day. Something like this code:

    Sub LookForNew()
    Dim n As String, msg As String, d As Date
    msg = ""
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set fils = fso.GetFolder("C:\Users\ User\Desktop\New folder (3)").Files
    For Each fil In fils
    n = fil.Name
    d = fil.DateCreated
    If d >= Date - 1 Then
    msg = msg & n & vbTab & d & vbCrLf
    End If
    Next fil
    If msg = "" Then
    MsgBox "No new files"
    Else
    MsgBox msg
    End If
    Set fso = Nothing
    End Sub

    The problem is that I don't know how to add this loop in this code to search each project folder.

    Thank you so much!
    Last edited by Nemesis339; 02-03-2023 at 03:00 PM.

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,942

    Re: VBA Code for specific subfolder

    Set a reference to MS Scripting Runtime, and use this code - change the path as needed.

    Please Login or Register  to view this content.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Registered User
    Join Date
    02-24-2022
    Location
    Romania
    MS-Off Ver
    360
    Posts
    4

    Re: VBA Code for specific subfolder

    It shows "type mismatch" when I want to run.

    Set schFolder = sFolder.Path & "\Schedule"

  4. #4
    Registered User
    Join Date
    02-24-2022
    Location
    Romania
    MS-Off Ver
    360
    Posts
    4

    Re: VBA Code for specific subfolder

    Quote Originally Posted by Bernie Deitrick View Post
    Set a reference to MS Scripting Runtime, and use this code - change the path as needed.

    Please Login or Register  to view this content.
    It shows "type mismatch" when I want to run.

    Set schFolder = sFolder.Path & "\Schedule"
    Last edited by Nemesis339; 02-03-2023 at 03:07 PM.

  5. #5
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,942

    Re: VBA Code for specific subfolder

    Sorry - I had some fat fingers AND I forgot to use GetFolder!

    Replace

    Please Login or Register  to view this content.
    with
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    02-24-2022
    Location
    Romania
    MS-Off Ver
    360
    Posts
    4

    Re: VBA Code for specific subfolder

    It works now.

    Thank you so much!
    You're a genius!

+ 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] Is there a way to get Specific subfolder level names and put in a column
    By jrtraylor in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-18-2019, 01:59 AM
  2. Replies: 14
    Last Post: 09-18-2016, 08:13 AM
  3. Replies: 0
    Last Post: 09-18-2015, 03:20 AM
  4. Mark email 'Read' in specific subfolder
    By delaing in forum Outlook Programming / VBA / Macros
    Replies: 4
    Last Post: 07-21-2015, 05:53 PM
  5. [SOLVED] SubFolder search but for specific file type
    By jquintana83 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 09-26-2014, 10:05 AM
  6. VBA code needed to move from Outlook 2010 subfolder to Symantec Vault subfolder
    By Marijke in forum Outlook Programming / VBA / Macros
    Replies: 1
    Last Post: 01-09-2014, 12:14 PM
  7. Moving an e-mail from a subfolder in Mailbox to the equivalent subfolder in an archive PST
    By johncassell in forum Outlook Programming / VBA / Macros
    Replies: 0
    Last Post: 07-09-2012, 11:31 AM

Tags for this Thread

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