+ Reply to Thread
Results 1 to 17 of 17

move specific files from directory to another without using cells

  1. #1
    Forum Contributor
    Join Date
    02-08-2021
    Location
    africa
    MS-Off Ver
    2016
    Posts
    410

    move specific files from directory to another without using cells

    Hello Guys !
    I have files are their names ("DATA_MONTLY" , "REPORTS RETURNS_MAR" , " INVOICES ARCHIVE") in this directory C:\Users\PC-MKK\Downloads\
    what I want moving theses files to this directory D:\Users\PC-MKK\dektop\ MONTHLY FILES\ and if one of them is not existed then should pop up message " the file name is ..... not existed. I want to that without using cells just directly .
    thanks

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

    Cool Hello, try this …


    According to your explanation a VBA demonstration for a starting point
    as you should be more accurate with directories like files names (v2) :

    PHP Code: 
    Sub Demo1()
      Const 
    "D:\Users\PC-MKK\dektop\ MONTHLY FILES\", S = "C:\Users\PC-MKK\Downloads\", C = vbLf & vbLf
        Dim IL, L
            If Dir(B, 16) = "" Then Beep: Exit Sub
            IL = [{"
    DATA_MONTLY","REPORTS RETURNS_MAR"," INVOICES ARCHIVE"}]
        For L = 1 To UBound(IL)
            If Dir(S & IL(L)) = IL(L) Then
                If Dir(B & IL(L)) = IL(L) Then Kill B & IL(L)
                Name S & IL(L) As B & IL(L)
                IL(L) = False
            End If
        Next
            IL = Filter(IL, False, False)
            If UBound(IL) > -1 Then MsgBox "
    Not found in " & S & " " & C & Application.Transpose(Join(IL, C)), , "Control"
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 04-17-2022 at 05:22 AM. Reason: movie optimization !

  3. #3
    Forum Contributor
    Join Date
    02-08-2021
    Location
    africa
    MS-Off Ver
    2016
    Posts
    410

    Re: move specific files from directory to another without using cells

    thanks but pops up path/ file access error in this line
    Please Login or Register  to view this content.
    I'm sure about the right path for two directories

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

    Arrow Re: move specific files from directory to another without using cells


    As it well works on my side with correct directories & files names so check the attributes of the file raising the error …

  5. #5
    Forum Contributor
    Join Date
    02-08-2021
    Location
    africa
    MS-Off Ver
    2016
    Posts
    410

    Re: move specific files from directory to another without using cells

    I create new file ,then the error is gone , but why tell me the files are not existed in this directory C:\Users\PC-MKK\Downloads\ despite of I use copy & paste to match the names into code with the files names to avoid sensitive spaces . do you have any idea?

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

    Arrow Re: move specific files from directory to another without using cells


    Just compare the attributes between both files …

  7. #7
    Forum Contributor
    Join Date
    02-08-2021
    Location
    africa
    MS-Off Ver
    2016
    Posts
    410

    Re: move specific files from directory to another without using cells

    what do you mean ?
    the files are pdf or xlsx

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

    Arrow Re: move specific files from directory to another without using cells


    No, the files attributes like you can see in their properties with Windows Explorer, see with your IT if necessary …

    Hoping you have filled the IL array with the files extension like pdf, xlsx, …

  9. #9
    Forum Contributor
    Join Date
    02-08-2021
    Location
    africa
    MS-Off Ver
    2016
    Posts
    410

    Re: move specific files from directory to another without using cells

    I don't understand what you mean IT .
    this is the setting for attributes of the file in my pc
    Attached Images Attached Images
    Last edited by MKLAQ; 04-16-2022 at 12:11 PM.

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

    Arrow Re: move specific files from directory to another without using cells


    With normal attribute then the issue may come from specific characters like from other OS than Windows,
    just try to rename the file(s), that's all I can guess without any further information …

  11. #11
    Forum Contributor
    Join Date
    02-08-2021
    Location
    africa
    MS-Off Ver
    2016
    Posts
    410

    Re: move specific files from directory to another without using cells

    actually I tried to rename the file(s), but doesn't work, anyway thanks for your time
    maybe some body has another option.

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

    Question Re: move specific files from directory to another without using cells


    What are actually your corrections for the constants and the array variable IL ? ('cause your initial post seems wrong …)

    Post #2 demonstration amended in case you do not enter valid filenames in the array …
    Last edited by Marc L; 04-17-2022 at 05:24 AM.

  13. #13
    Forum Contributor
    Join Date
    02-08-2021
    Location
    africa
    MS-Off Ver
    2016
    Posts
    410

    Re: move specific files from directory to another without using cells

    it gives sound Beep when run the macro

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

    Arrow Re: move specific files from directory to another without using cells


    As this beep means the destination directory within constant B does not exist ! …

  15. #15
    Forum Contributor
    Join Date
    02-08-2021
    Location
    africa
    MS-Off Ver
    2016
    Posts
    410

    Re: move specific files from directory to another without using cells

    even if the directory is correct , it still shows message the files are not found in this C:\Users\PC-MKK\Downloads\:
    DATA_MONTLY
    REPORTS RETURNS_MAR
    INVOICES ARCHIVE
    I attach the file & picture for my files names in folder, may be you find out the problem like office-version or else thing
    Attached Images Attached Images
    Attached Files Attached Files

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

    Arrow Re: move specific files from directory to another without using cells


    Yes 'cause those files do not exist ! As I warned in post #8 you forgot the extension like file.pdf or file.xlsx
    so just check obviously the complete filenames then update the VBA procedure accordingly …

  17. #17
    Forum Contributor
    Join Date
    02-08-2021
    Location
    africa
    MS-Off Ver
    2016
    Posts
    410

    Re: move specific files from directory to another without using cells

    I warned in post #8 you forgot the extension like file.pdf or file.xlsx
    my apologies ! much appreciated for help

+ 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. Replies: 1
    Last Post: 02-22-2019, 07:52 PM
  2. [SOLVED] macro to copy excel files only from main directory and sub directory to a specific folder
    By JEAN1972 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-05-2019, 09:49 AM
  3. Macro to Move files from one directory to other directory
    By Shanthuday in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-05-2013, 07:21 AM
  4. 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
  5. Macro to move files from one directory to another
    By Barb Reinhardt in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-21-2006, 12:40 PM
  6. Move all files from one directory to another
    By Prema in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-14-2005, 07:09 PM
  7. [SOLVED] move all files in a directory into another
    By michael_mcclellan@hotmail.com in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-24-2005, 12:06 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