+ Reply to Thread
Results 1 to 33 of 33

Search for pdf files by date or title

Hybrid View

  1. #1
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Search for pdf files by date or title

    hmm i may have over thought...though i am unsure of duplication would be an issue but
    the search string can override the need to write in files

    Sub FName()
    
        Dim strFileName As String
        Const strFolder As String = "C:\Downloads\" 'Directory
        Dim pos As Long
        Dim InvNum As String
        Dim strSearch As String
        
        
        strFileName = Dir(strFolder & "*.pdf") 'list filenames only with .pdf
        i = 7 'starting row
        Range("B7:D50").ClearContents 'clear previous searchs ...extend pass 50 if you have more than 50
        
        strSearch = Range("B4").Value 'search term
        
        
        Do While strFileName <> vbNullString 'loop for filenames in folder
                
            If InStr(strFileName, strSearch) > 0 Then 'if search term found in filename then go ahead
            
                pos = InStr(strFileName, "-") 'position of first -
                
                If pos <> 0 Then ' check delimiter is found
        
                    Cells(i, 2).Value = Left(strFileName, pos - 1) 'Name
                    InvNum = Mid(strFileName, pos + 2) 'inv num - date.pdf
                    Cells(i, 4).Value = Replace(Right(InvNum, Len(InvNum) - InStr(InvNum, "-")), ".pdf", "") 'Date minus the .pdf
                    Cells(i, 3).Value = Left(InvNum, InStr(InvNum, "-") - 1) 'extract Inv Num
                    
                End If
                
                i = i + 1 ' increment row
            End If
            
            strFileName = Dir 'next file
            
        Loop
    End Sub
    instr is case sensitive if that is an issue need to UPPER or LOWER everything first
    Last edited by humdingaling; 05-20-2015 at 02:08 AM.
    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

+ 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. many workbooks title into cell after search
    By mrjackt in forum Excel General
    Replies: 0
    Last Post: 03-05-2015, 08:58 AM
  2. Need to search array and return value along with title and row values
    By wilburr in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 09-28-2013, 06:01 AM
  3. [SOLVED] Search files until date is found
    By twckfa16 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-09-2013, 02:57 PM
  4. Using cell contents to search for corresponding sheet title
    By teblowtime in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-30-2013, 03:31 PM
  5. Replies: 3
    Last Post: 04-08-2012, 06:52 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