Results 1 to 3 of 3

Create FOLDER in subfoldesr and move folders with specific names into FOLDER

Threaded View

  1. #1
    Registered User
    Join Date
    12-01-2008
    Location
    India
    MS-Off Ver
    Microsoft 365 Enterprise - Excel version2301
    Posts
    69

    Create FOLDER in subfoldesr and move folders with specific names into FOLDER

    Hi,

    the below code creates a "2013" Folder in all the subfolder and move any "FILE having 2013 in it's name" to "2013" Folder, is it possible to move any "SUBFOLDER that has 2013 in it's name" to "2013" Folder? Current code moves only Files that have 2013 in their name but not subfolders that have 2013 in their name.

    Sub AddSubfolder()
    'Under tools, add reference to Microsoft Scripting Runtime
    Dim FSO As Scripting.FileSystemObject
    Dim RootFolder As Object
    Dim SubFolder As Object
    Dim myFolder As String
    Dim myNewFolder As String
    Dim mySubfolderPath As String
    Dim myFile As String
    Set FSO = CreateObject("Scripting.FileSystemObject")
    myFolder = "D:\Users\703038355\Desktop\oFile\" 'Change to identify your main folder
    Set RootFolder = FSO.GetFolder(myFolder)
    For Each SubFolder In RootFolder.SubFolders
    Debug.Print SubFolder.Path
    mySubfolderPath = SubFolder.Path
    myNewFolder = mySubfolderPath & "\2013"
    If Not FSO.FolderExists(myNewFolder) Then
    MkDir (myNewFolder)
    myFile = Dir(mySubfolderPath & "\*2013*")
    Do While myFile <> ""
    FSO.MoveFile mySubfolderPath & "\" & myFile, myNewFolder & "\" & myFile

    myFile = Dir
    Loop

    End If
    Next SubFolder

    End Sub
    Thanks in advance.

    Amar
    Last edited by Amarjeet Singh; 02-25-2015 at 09:56 AM. Reason: Code not in Quote

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Create folder and move folders
    By Amarjeet Singh in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-18-2015, 11:56 AM
  2. [SOLVED] Create new folder and sub folders
    By Will_iam in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-10-2013, 04:10 AM
  3. Improvement - Option To Nest Folders as Sub Folder Under a Main Folder / Heading
    By :) Sixthsense :) in forum Suggestions for Improvement
    Replies: 4
    Last Post: 01-28-2013, 07:09 AM
  4. Replies: 6
    Last Post: 08-11-2006, 03:41 PM
  5. Replies: 2
    Last Post: 05-07-2006, 03:20 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