+ Reply to Thread
Results 1 to 19 of 19

How to copy Jpeg files from one folder to another folder with file name reference in excel

  1. #1
    Registered User
    Join Date
    08-21-2017
    Location
    UAE
    MS-Off Ver
    office 365 proplus
    Posts
    17

    Post How to copy Jpeg files from one folder to another folder with file name reference in excel

    Hi all,

    How to copy Jpeg files from one folder to another folder with file name reference in excel. Eg. as below

    I want to do medical insurance for my employees, for which I need to send their photos. I have all photos of staff and workers in one folder with their employee number as file name.jpg.

    I want to select only worker's photos and copy them to another folder to share the same to the insurance agency, with reference to their employee number as base reference.

    Eg:
    Pic file name in a folder as below
    9100567.jpg
    9100486
    9101592

    name list in excel as below
    Emp.No
    9100567
    9100486
    9101592

    please help me to get this automation to solve my time-consuming work.

    Thanks
    Raghavan

  2. #2
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: How to copy Jpeg files from one folder to another folder with file name reference in e

    Hi,

    Perhaps this
    Please Login or Register  to view this content.
    Last edited by xlnitwit; 09-28-2017 at 06:11 AM.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  3. #3
    Registered User
    Join Date
    08-21-2017
    Location
    UAE
    MS-Off Ver
    office 365 proplus
    Posts
    17

    Re: How to copy Jpeg files from one folder to another folder with file name reference in e

    Dear xlnitwit,

    Tried that macro, but giving runtime error 53, while debugging this line is being selected

    FileCopy fromPath & cell.Value & "jpg", toPath & cell.Value & "jpg"

  4. #4
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: How to copy Jpeg files from one folder to another folder with file name reference in e

    I've corrected the code- I had omitted two full stops.

  5. #5
    Registered User
    Join Date
    08-21-2017
    Location
    UAE
    MS-Off Ver
    office 365 proplus
    Posts
    17

    Re: How to copy Jpeg files from one folder to another folder with file name reference in e

    so where to correct the code now?

  6. #6
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: How to copy Jpeg files from one folder to another folder with file name reference in e

    Use the revised version above.

  7. #7
    Registered User
    Join Date
    08-21-2017
    Location
    UAE
    MS-Off Ver
    office 365 proplus
    Posts
    17

    Re: How to copy Jpeg files from one folder to another folder with file name reference in e

    I have done this code with correction of my file path, but still the same runtime error 53 is coming. I don't know where i'm going wrong. please correct me.

    Sub copyPictures()
    Dim cell As Range
    Dim fromPath As String
    Dim toPath As String

    fromPath = "C:\Named"
    toPath = "C:\Named\Selected"

    If Right$(fromPath, 1) <> "\" Then fromPath = fromPath & "\"
    If Right$(toPath, 1) <> "\" Then toPath = toPath & "\"

    For Each cell In Range("A2:A526")

    FileCopy fromPath & cell.Value & ".jpg", toPath & cell.Value & ".jpg"
    Next cell
    End Sub

  8. #8
    Registered User
    Join Date
    08-21-2017
    Location
    UAE
    MS-Off Ver
    office 365 proplus
    Posts
    17

    Re: How to copy Jpeg files from one folder to another folder with file name reference in e

    Below pic for ref.

    Debug.JPGDebug1.JPG

  9. #9
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: How to copy Jpeg files from one folder to another folder with file name reference in e

    Either one of the file names doesn't exist, or one (or both) of the folder paths doesn't.

  10. #10
    Registered User
    Join Date
    08-21-2017
    Location
    UAE
    MS-Off Ver
    office 365 proplus
    Posts
    17

    Re: How to copy Jpeg files from one folder to another folder with file name reference in e

    My picture file name is in a folder as below (without ".jpg") for understanding the file format i've given filename.jpg
    9100567
    9100486
    9101592

    name list in excel as below
    Emp.No
    9100567
    9100486
    9101592

    correct me what correction to be made in the code

  11. #11
    Registered User
    Join Date
    08-21-2017
    Location
    UAE
    MS-Off Ver
    office 365 proplus
    Posts
    17

    Re: How to copy Jpeg files from one folder to another folder with file name reference in e

    Tried the below by removing &".jpg", but it copied only one file to the specified location.
    Sub copyPictures()
    Dim cell As Range
    Dim fromPath As String
    Dim toPath As String

    fromPath = "C:\Named"
    toPath = "C:\Named\Selected"

    If Right$(fromPath, 1) <> "\" Then fromPath = fromPath & "\"
    If Right$(toPath, 1) <> "\" Then toPath = toPath & "\"

    For Each cell In Range("A2:A526")

    FileCopy fromPath & cell.Value, toPath & cell.Value
    Next cell
    End Sub

  12. #12
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: How to copy Jpeg files from one folder to another folder with file name reference in e

    If you get an error 53 then the file name is wrong. There is no other cause.

  13. #13
    Registered User
    Join Date
    08-21-2017
    Location
    UAE
    MS-Off Ver
    office 365 proplus
    Posts
    17

    Re: How to copy Jpeg files from one folder to another folder with file name reference in e

    By using the below code, when i run the macro it throws runtime error 53 and while pressing debug. it completed the file copy till 99 files to the specified folder, any changes to be made for the cells in rows of 500 plus. i have mentioned A2:A526 and changed the excel numbersplus .jpg for executing and the result as said above.

    eg. name in excel sheet as 9100567.jpg and so on...

    Sub copyPictures()
    Dim cell As Range
    Dim fromPath As String
    Dim toPath As String

    fromPath = "C:\Named"
    toPath = "C:\Named\Selected"

    If Right$(fromPath, 1) <> "\" Then fromPath = fromPath & "\"
    If Right$(toPath, 1) <> "\" Then toPath = toPath & "\"

    For Each cell In Range("A2:A526")

    FileCopy fromPath & cell.Value, toPath & cell.Value
    Next cell
    End Sub

    I don't know how to attache my excel file for your ref.

  14. #14
    Registered User
    Join Date
    08-21-2017
    Location
    UAE
    MS-Off Ver
    office 365 proplus
    Posts
    17

    Re: How to copy Jpeg files from one folder to another folder with file name reference in e

    Hope I have attached the file. please correct me if the code is wrong.
    Attached Files Attached Files

  15. #15
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: How to copy Jpeg files from one folder to another folder with file name reference in e

    The file will not help. If it completed 99 copies, then the file name of the 100th one must be incorrect.

  16. #16
    Registered User
    Join Date
    08-21-2017
    Location
    UAE
    MS-Off Ver
    office 365 proplus
    Posts
    17

    Re: How to copy Jpeg files from one folder to another folder with file name reference in e

    Let me check for that too...

  17. #17
    Registered User
    Join Date
    08-21-2017
    Location
    UAE
    MS-Off Ver
    office 365 proplus
    Posts
    17

    Re: How to copy Jpeg files from one folder to another folder with file name reference in e

    Great job Mr Xlnitwit, thanks and you made my day. The job was done. thank you very much.

  18. #18
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: How to copy Jpeg files from one folder to another folder with file name reference in e

    You're welcome. Please remember to mark the thread Solved.

  19. #19
    Registered User
    Join Date
    08-21-2017
    Location
    UAE
    MS-Off Ver
    office 365 proplus
    Posts
    17

    Re: How to copy Jpeg files from one folder to another folder with file name reference in e

    Marked my thread 'Solved'

+ 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. Create folder and move files to that folder based on file name
    By biznez in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-26-2016, 06:58 PM
  2. [SOLVED] Copy certain files from Source folder to Destination folder
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-16-2015, 08:56 PM
  3. Replies: 12
    Last Post: 03-09-2015, 05:52 PM
  4. Copy excel and text files from one folder to another folder...
    By annupojupradeep in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-26-2014, 06:34 AM
  5. Macro to copy the value of some cells in excel files in a folder to a master file
    By phemocheee in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-17-2013, 08:33 AM
  6. Macro to copy some cells in some excel files in a folder to a master file
    By phemocheee in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-17-2013, 04:40 AM
  7. [SOLVED] VBA Code open files in folder, copy text to workbook-Next time folder opened copy only new
    By Bikeman in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-02-2013, 07:59 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