vba - Search all columns in an excel column and check value against file name in folder to see if exists? -


i have folder .txt files:

\\uksh000-file06\sharedareas\1.0 hewden public\ns\approval 

each text file has random name so:

ns123shs.txt nsg234eh.txt nsds3461.txt 

most of files file names (minus extenstion .txt) in excel sheet in column c.

ns123shs nsds3461 

i trying scan column c check if filename found in folder directory , if yes show message saying found, else show message saying not found.

so far i've been able figure out how scan column specific value, define, want able scan entire column, , compare each value see if exists in folder?

can please show me how might please? thanks

private sub workbook_open()  dim findstring string dim rng range findstring = "nsds3461" if trim(findstring) <> ""     sheets("home").range("c:c") 'searches of column         set rng = .find(what:=findstring, _                         after:=.cells(.cells.count), _                         lookin:=xlvalues, _                         lookat:=xlwhole, _                         searchorder:=xlbyrows, _                         searchdirection:=xlnext, _                         matchcase:=false)         if not rng nothing              msgbox "found" 'value not found         else             msgbox "reference not found" 'value not found         end if     end  end if 

in code bellow you'll have update worksheets(1) sheet index have file names, , folder_path info:

\\uksh000-file06\sharedareas\1.0 hewden public\ns\approval

.

option explicit  private sub workbook_open()      const folder_path   string = "c:\temp\"     const file_name_col long = 3      dim filenames variant, ws worksheet, long     dim fname string, result string      set ws = worksheets(1)      filenames = ws.usedrange.columns(file_name_col)      = 2 ubound(filenames)          fname = trim(filenames(i, 1))          if len(dir(folder_path & fname)) > 0             fname = fname & vbtab & ": found" & vbcrlf         else             fname = fname & vbtab & ": not found" & vbcrlf         end if          result = result & - 1 & ". " & vbtab & fname     next      msgbox result, , "search result"  end sub 

.

result:

enter image description here

hope helps


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -