+ Reply to Thread
Results 1 to 3 of 3

VB Code to move files based on its name

  1. #1
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    VB Code to move files based on its name

    Hello:

    I have lots of pdf file in C:\Scannedfiles folder with following name standard.

    MM-DD-YYYY-StoreName-Category.pdf

    Example
    05-09-2020-Store1-Utilies_Gas
    04-29-2020-Store9-Insurance_WC


    I need VB Code to move all these files in their respective folder for each store.


    C:\Store1\Utililies
    C:\Store9\Insurance.

    If folder does not exist then create one.

    Please let me know if you have any questions.
    Thanks.

    Riz

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: VB Code to move files based on its name

    Please Login or Register  to view this content.
    Last edited by AlphaFrog; 05-21-2020 at 02:13 AM.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hi ! Give it a try !


    For 2010 & upper Windows versions only to paste to the top of a module (for previous Windows versions just remove PtrSafe) :

    PHP Code: 
    Private Declare PtrSafe Function MakeSureDirectoryPathExists Lib "imagehlp.dll" (ByVal DirPath$) As Boolean

    Sub Demo1
    ()
        Const 
    "C:\", P = D & "Scannedfiles\"
          Dim F$, S$(), T$
              F = Dir(P & "
    ??-??-????-*-*.pdf")
        While F > ""
              S = Split(Split(F, "
    _")(0), "-")
              T = D & S(3) & "
    \" & S(4) & "\"
              MakeSureDirectoryPathExists T
              Name P & F As T & F
              F = Dir
        Wend
    End Sub 
    ► Do you like it ? ► ► So thanks to click on bottom left star icon « Add Reputation » ! ◄ ◄
    Last edited by Marc L; 05-21-2020 at 08:37 AM. Reason: add comment …

+ 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. VBA code to automatically move files to subfolders based on a predefined list
    By mkh862 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 06-11-2022, 07:34 PM
  2. VB Code to move the pdf files
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 04-15-2016, 08:25 PM
  3. [SOLVED] VB Code to Move Files
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 10-27-2015, 02:16 PM
  4. VBA code to move multiple files to different folders based on the file name
    By MissaLissa in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-07-2015, 10:19 AM
  5. [SOLVED] VBA Code to Move Excel files from one folder to another
    By MHamid in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 09-04-2013, 12:33 PM
  6. Problem with code - move files to another directory
    By uncleslinky in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-14-2011, 10:06 AM
  7. Move Files Based On date in Name
    By erock24 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-02-2009, 06:32 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