+ Reply to Thread
Results 1 to 6 of 6

Help:) To find files and copy to new location - filesystem object.

  1. #1
    Registered User
    Join Date
    11-05-2014
    Location
    England
    MS-Off Ver
    2010
    Posts
    4

    Smile Help:) To find files and copy to new location - filesystem object.

    Hello,

    I wonder if anyone can help me with a macro.

    I have an excel sheet listing product data including image filenames. So far I have a macro which reads the list of filenames then checks a file location to see if the file exists. If the file exists then "Yes" is entered and if not then "No" is entered to the appropriate data row.

    I'd like to finish this by copying the file if it exists and place it in a new location, but I don't have a clue where to start with this one.

    Here is the code I have so far.
    **************************
    ' Sub Check_File_Existance()
    Dim lRow&, cRow&, ImageName$
    Dim WS_Csv As Worksheet

    Application.ScreenUpdating = False

    ' to work on activesheet
    Set WS_Csv = ActiveSheet

    With WS_Csv
    ' decide last row of CSV
    lRow = .Cells(Rows.Count, "A").End(xlUp).Row

    For cRow = 2 To lRow
    ImageName = .Cells(cRow, "B").Value

    ' check if image exists or not
    If Dir("D:\www\mywebsite.uk\image\data\" & ImageName) = vbNullString Then
    .Cells(cRow, "AA") = "No"
    Else
    .Cells(cRow, "AA") = "Yes"
    End If
    Next
    End With

    Application.ScreenUpdating = True

    End Sub
    **********************************

    I would like the files which exist to be copied to D:\www\mywebsite.uk\image\data\filesfound\

    Any help or guidance would be appriciated, thanks.

  2. #2
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Help:) To find files and copy to new location - filesystem object.

    Try

    Please Login or Register  to view this content.
    If you like my contribution click the star icon!

  3. #3
    Registered User
    Join Date
    11-05-2014
    Location
    England
    MS-Off Ver
    2010
    Posts
    4

    Re: Help:) To find files and copy to new location - filesystem object.

    Hi OllieB,

    Many thanks for your quick reponse, can you help me a little further?

    Do I use the code you have provided in place of the code I already have or do I add your code after the existing macro?

    Regards

    CosyDan6

  4. #4
    Registered User
    Join Date
    11-05-2014
    Location
    England
    MS-Off Ver
    2010
    Posts
    4

    Re: Help:) To find files and copy to new location - filesystem object.

    Here is whats happening now.

    I added the code provided by OllieB after my existing macro shown in the first post.

    I'm using Office 2010 and the macro is stored in the default personal.xlsb file.

    When I run OllieB's macro it appears the hang for about 4 minutes but is actually running.

    When the macro completes it has entered "No" in coloumn "AA" of the personal.xlsb file, not the file I'm working on which has the data. It has entered "No" in over 104,000 rows but there are less than 500 rows of original data.

    No files are being coppied to the filesfound folder.

    Any further assitance would be appriciated, thanks.

    CosyDan6
    Last edited by CosyDan6; 05-08-2015 at 10:04 AM.

  5. #5
    Registered User
    Join Date
    11-05-2014
    Location
    England
    MS-Off Ver
    2010
    Posts
    4

    Re: Help:) To find files and copy to new location - filesystem object.

    I managed to finally find out why the code didn't work for me.

    I simply changed "With ThisWorkbook.ActiveSheet" to "With ActiveSheet"

    Thanks

  6. #6
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Help:) To find files and copy to new location - filesystem object.

    Please note that the line

    Please Login or Register  to view this content.
    ensures that the actions take place on the active worksheet in the same workbook where the code is located. Changing it to just Activesheet will allow to run the code to run against the current active worksheet which could be in a different workbook if you have multiple workbooks open. Your change therefore is unlikely to be the reason for the code to start working.

    The problem was most likely due to the statement

    Please Login or Register  to view this content.
    which tries to find the last row in use on the worksheet by starting in Cell A1 and moving down to the last filled cell in that column.

    But anyway, glad to hear it is working now

+ 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. Need to copy files to new location using column in Excel
    By traygivin in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-02-2014, 04:53 PM
  2. Adding FileSystem Object to my current macro
    By dark91zc in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-08-2013, 12:15 PM
  3. Automatic copy of Excel files to a new location
    By lexx8008 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-11-2013, 06:09 PM
  4. [SOLVED] Copy files from listbox and paste in user defind location
    By klonbeck in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-14-2012, 12:35 PM
  5. Use Excel to copy files to a location in disc
    By sp_key in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-21-2009, 12:07 PM

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