+ Reply to Thread
Results 1 to 24 of 24

VBA code that cut .pdf files and copy in respective folders

  1. #1
    Forum Contributor
    Join Date
    07-25-2012
    Location
    Pakistan
    MS-Off Ver
    Excel 2010
    Posts
    178

    VBA code that cut .pdf files and copy in respective folders

    Hi all VBA fox

    I have a main folder and three sub folders Name:Official Field Private (sub folders are empty) in main folder files in .pdf format present ..... A excel file where three kinds of number present as in Sample file shows............i want and need a code cut .pdf files and copy in respective folders by matching these numbers from excel file.

    May be i elaborate my question.
    I have Office 2013.

    Regards
    Attached Files Attached Files

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: VBA code that cut .pdf files and copy in respective folders

    So the PDF names would be:

    456987.pdf
    985423.pdf
    3545465.pdf
    ??
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Contributor
    Join Date
    07-25-2012
    Location
    Pakistan
    MS-Off Ver
    Excel 2010
    Posts
    178

    Re: VBA code that cut .pdf files and copy in respective folders

    Thanks JB

    Yes the file name 456987.pdf

    Regards

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: VBA code that cut .pdf files and copy in respective folders

    Try this then.... it will highlight the filenames it can't find.

    Untested:
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    07-25-2012
    Location
    Pakistan
    MS-Off Ver
    Excel 2010
    Posts
    178

    Re: VBA code that cut .pdf files and copy in respective folders

    Thanks Alot JB
    If u plz guide me from where should i start ? Steps plz ?

    REgards

  6. #6
    Forum Contributor
    Join Date
    07-25-2012
    Location
    Pakistan
    MS-Off Ver
    Excel 2010
    Posts
    178

    Re: VBA code that cut .pdf files and copy in respective folders

    I try it any way
    A main folder all sub folder in their (Official Field Private) a excel file containing all number colomn vise (Official Field Private).
    Then i run Macro it just highlighted the numbers and change the color only.

    Guide needed.
    REgards

  7. #7
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: VBA code that cut .pdf files and copy in respective folders

    You read through the macro and corrected the path it is supposed to use to find the files? Once that is edited make sure that sheet with the list of files you uploaded is onscreen, and run the macro.

  8. #8
    Forum Contributor
    Join Date
    07-25-2012
    Location
    Pakistan
    MS-Off Ver
    Excel 2010
    Posts
    178

    Re: VBA code that cut .pdf files and copy in respective folders

    fPATH = "C:\Path\To\Main\Folder\" 'remember the final \

    On this line i changed the path and then try but nothing happen.....If u can test the code.
    Regards

  9. #9
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: VBA code that cut .pdf files and copy in respective folders

    THe code was tested prior to posting to you. I created 3 files and it moved them accordingly, all the rest were marked in red since I didn't create those.

  10. #10
    Forum Contributor
    Join Date
    07-25-2012
    Location
    Pakistan
    MS-Off Ver
    Excel 2010
    Posts
    178

    Re: VBA code that cut .pdf files and copy in respective folders

    May be i am doing something wrong.......

  11. #11
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: VBA code that cut .pdf files and copy in respective folders

    Well, the macro goes into a standard code module (Insert > Module)

    Here's a tiny tweak on the macro to help "create" those folders if they don't exist, also changed the highlight color.
    Please Login or Register  to view this content.


    Here you can see the macro working: http://screencast.com/t/qAQw2xSKqgiA

  12. #12
    Forum Contributor
    Join Date
    07-25-2012
    Location
    Pakistan
    MS-Off Ver
    Excel 2010
    Posts
    178

    Re: VBA code that cut .pdf files and copy in respective folders

    Thanks alot JB

    I run the Macro it gives error " Path Not Found"
    fPATH = "D:\Waqar Per\Excel Folder check\ 'remember the final \" (I change the path here only)

    Excel folder check is a folder which contain 300 pdf files Three sub folders (Official Field Private) and A excel file (Which have three coloumn Official Field Private, Each coloumn have 100 plus numbers)
    I run your Macro in this excel file.

    Guidance needed
    Regards

  13. #13
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: VBA code that cut .pdf files and copy in respective folders

    I've written a macro, I've recorded a video showing you it is working, and you're getting a very specific error message telling you something is wrong with the path. I've done all I can from my end, you'll have to figure out what's wrong with your path.

    Surely you mean this:
    Please Login or Register  to view this content.

    Notice the quote marks go around the path, not the comment?

  14. #14
    Forum Contributor
    Join Date
    07-25-2012
    Location
    Pakistan
    MS-Off Ver
    Excel 2010
    Posts
    178

    Re: VBA code that cut .pdf files and copy in respective folders

    Thanks alot JB

    I missed " only i put that
    Now when i run macro it just color the the whole coloumn where the number is.
    Main folder sill have all 300 pdf files and sub folder still empty.

    Any guidance u can give me.....
    Regards

  15. #15
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: VBA code that cut .pdf files and copy in respective folders

    The video shows it will move the file if the path is correct and the filenames exactly match a pdf. The path was wrong and you finally fixed that. One must now assume the names of the PDF files are somehow all wrong as well. My videos shows it will color the cells when the files are not found in the path, so it's doing the right thing for files it can't find. Something is amiss with your file names, on the sheet or on the hard drive.

  16. #16
    Forum Contributor
    Join Date
    07-25-2012
    Location
    Pakistan
    MS-Off Ver
    Excel 2010
    Posts
    178

    Re: VBA code that cut .pdf files and copy in respective folders

    Ok can u send me video . ([email protected])

    or Can u elaborate me more on excel sheet number should be 3456567.pdf or simple 3456567
    I think i just miss one thing......
    Regards
    Last edited by waqarqrl; 03-22-2013 at 03:51 AM.

  17. #17
    Forum Contributor
    Join Date
    07-25-2012
    Location
    Pakistan
    MS-Off Ver
    Excel 2010
    Posts
    178

    Re: VBA code that cut .pdf files and copy in respective folders

    Done

    It work now

    Thanks Alot

  18. #18
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: VBA code that cut .pdf files and copy in respective folders

    Glad to hear. What turned out to be the problem?

  19. #19
    Forum Contributor
    Join Date
    07-25-2012
    Location
    Pakistan
    MS-Off Ver
    Excel 2010
    Posts
    178

    Re: VBA code that cut .pdf files and copy in respective folders

    Thanks alot JB

    The Problem was the file name it did not match. Now fine.
    One more question still pending, Only Official is cut and paste, Field and private still not working

    Need little guidance
    Regards

  20. #20
    Forum Contributor
    Join Date
    07-25-2012
    Location
    Pakistan
    MS-Off Ver
    Excel 2010
    Posts
    178

    Re: VBA code that cut .pdf files and copy in respective folders

    Now it give Run time error 13



  21. #21
    Forum Contributor
    Join Date
    07-25-2012
    Location
    Pakistan
    MS-Off Ver
    Excel 2010
    Posts
    178

    Re: VBA code that cut .pdf files and copy in respective folders

    Sir JB

    Your slight help is needed.
    Regards

  22. #22
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: VBA code that cut .pdf files and copy in respective folders

    As demonstrated in the video I posted previously, the macro does work, all the problems so far have been examples of things not being in your system as you described. If the text in the cells B1 and C1 are correctly spelled and the text in the cells going down those columns match to real files in that main folder, they will be found and moved. The video proved that. You're going to have to continue to check your system and find the things that aren't right.

  23. #23
    Forum Contributor
    Join Date
    07-25-2012
    Location
    Pakistan
    MS-Off Ver
    Excel 2010
    Posts
    178

    Re: VBA code that cut .pdf files and copy in respective folders

    Hello Sir JBeaucaire

    Months ago u write this code for me it working fine.
    Today it give a error Error 75 and file/path access error.
    plz help me out i am too much worried.
    although i check the path
    Regards

  24. #24
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: VBA code that cut .pdf files and copy in respective folders

    From Microsoft:

    "Path/File access error (Error 75)

    During a file-access or disk-access operation, for example, Open, MkDir, ChDir, or RmDir, the operating system couldn't make a connection between the path and the file name. Possible cause:

    The file specification isn't correctly formatted.
    A file name can contain a fully qualified (absolute) or relative path. A fully qualified path starts with the drive name (if the path is on another drive) and lists the explicit path from the root to the file. Any path that isn't fully qualified is relative to the current drive and directory."

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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