+ Reply to Thread
Results 1 to 7 of 7

Vba to search in a folder for a file name that is either a pdf or excel work book

  1. #1
    Registered User
    Join Date
    05-14-2015
    Location
    Chicago, Illinios
    MS-Off Ver
    2007
    Posts
    35

    Vba to search in a folder for a file name that is either a pdf or excel work book

    Ok so i was given a list of Invoices (about a thousand) and i need to search each one in a subfolder to see if they were saved or not. If they were saved they are saved as the invoice number which makes it easier.

    So i wanted to create something where when i put an invoice number, say 2142072 into A1, it searches in this directory for a pdf or excel sheet titled 2142072:

    S:\Everyone\Invoices Sent Electronically\


    And if it does it copies that invoice number into a column titled "Found" or if it doesn't it puts it in a column called "not found"

    So every time i enter in a new invoice number into A1, it'll place that invoice number into the Found or not found column beneath the invoice it found or didn't find already.

    Is this possible?

  2. #2
    Valued Forum Contributor
    Join Date
    03-24-2014
    Location
    England
    MS-Off Ver
    Excel 2003 - 2016
    Posts
    575

    Re: Vba to search in a folder for a file name that is either a pdf or excel work book

    yes.

    The quickest and easiest way to determine if a file exists is to run a getattr command on it (to retrieve the file attributes). If the command errors then the file doesn't exist.

    ie

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    05-14-2015
    Location
    Chicago, Illinios
    MS-Off Ver
    2007
    Posts
    35

    Re: Vba to search in a folder for a file name that is either a pdf or excel work book

    look below
    Last edited by Pr0x1mo; 02-09-2017 at 12:18 PM.

  4. #4
    Registered User
    Join Date
    05-14-2015
    Location
    Chicago, Illinios
    MS-Off Ver
    2007
    Posts
    35

    Re: Vba to search in a folder for a file name that is either a pdf or excel work book

    Quote Originally Posted by BellyGas View Post
    yes.

    The quickest and easiest way to determine if a file exists is to run a getattr command on it (to retrieve the file attributes). If the command errors then the file doesn't exist.

    ie

    Please Login or Register  to view this content.
    Stupid question but is this exactly what i copy and paste onto vba?

  5. #5
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,784

    Re: Vba to search in a folder for a file name that is either a pdf or excel work book

    INSERT A MODUALE IN VBA AND PASTE THIS CODE THERE
    Please Login or Register  to view this content.
    Assuming you will put invoice number in Column A
    type this formula in B adjacent to the invoice number
    =IF(FileExistspdf(A1),"Found","Not found")
    DRAG
    Last edited by ImranBhatti; 02-09-2017 at 12:54 PM. Reason: Path corrected according to user's path
    Teach me Excel VBA

  6. #6
    Registered User
    Join Date
    05-14-2015
    Location
    Chicago, Illinios
    MS-Off Ver
    2007
    Posts
    35

    Re: Vba to search in a folder for a file name that is either a pdf or excel work book

    Ok, another dumb question, every time i put this in a module, and try to run it, it just pops up a blank message box asking me to select a macros i want to run.... do you run modules a different way or something?

  7. #7
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,784

    Re: Vba to search in a folder for a file name that is either a pdf or excel work book

    Quote Originally Posted by Pr0x1mo View Post
    Ok, another dumb question, every time i put this in a module, and try to run it, it just pops up a blank message box asking me to select a macros i want to run.... do you run modules a different way or something?
    If you are talking about post#6 code then
    You don't have to run it at all.just save it there and close the vbe .
    You need to put the formula in the cell adjacent to the invoice number on the sheet.the formula is

    =IF(FileExistspdf(A1),"Found","Not found")
    Just like any built in formulas like sum ,sumif etc.

+ 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. [SOLVED] Save Sheets as PDF in same destination folder as Work book.
    By Jwilf in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 11-09-2016, 04:59 PM
  2. macro for split work book and save it in to new folder
    By ikshanu in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-10-2015, 01:19 PM
  3. Search Folder + Search Excel File and Sum
    By Vanda_a in forum Excel General
    Replies: 1
    Last Post: 03-06-2015, 12:00 PM
  4. Import external file in excel work book.
    By winmaxservices1 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-04-2015, 10:06 AM
  5. Can excel gather data from every work book in a folder?
    By McCool in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-22-2013, 06:12 AM
  6. [SOLVED] Periodical Merging of multiple Excel work book in shared folder
    By dhandapaniv in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-14-2012, 02:32 AM
  7. [SOLVED] how to select a work book from a folder using macros
    By preventhospitalvisit in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 04-09-2012, 12:45 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