excel - Search result files needs to be looped through -


the code written below searches file user provided name , shows in message box. can stored in array when required , search result files can opened , looped read content of search result files


 private sub cmdsubmit_click()   if me.part_number.value = ""     msgbox "please enter part number.", vbexclamation, "part search"     me.part_number.setfocus     exit sub  end if    if me.id_tag.value = ""     msgbox "please select id tag.", vbexclamation, "part search"     me.id_tag.setfocus     exit sub  end if   call flist   end sub  sub flist()    dim mylist dim fldr string, fltr string, stemp string, shldr string dim long dim msg string dim filecount integer    filecount = 0    fldr = "c:\users\op\desktop\new folder" if right$(fldr, 1) <> "\" fldr = fldr & "\" fltr = (me.part_number.value & "*.xls")  msg = fltr & " files found:" & vblf shldr = dir(fldr & fltr) while shldr <> ""     stemp = stemp & "|" & shldr     shldr = dir loop if stemp <> ""     mylist = split(stemp, "|")     = 1 ubound(mylist)         msg = msg & vblf & mylist(i)     next else     msg = msg & vblf & "none" end if msgbox msg   end sub 

you seem have lost end sub's.

you can either copy code between (but not including) sub flist() , end sub end of first code (just before end sub) or use

call flist 

again, before end sub of click event.

added user have enter thefile.gif or thefiles.* in order find files using dir. if enter something part_number looking (single) folder of name, or file of name (without extension).

added in response further comment. if user enters "1" part_number code find files begin "1", string. want find files begin number you'll have write code constructs these filenames, in loop:

for x = 1 800 

if enter "banana1" , want find files "banana1", "banana2" you'll need remove "1" end of text and, again, files in loop. reduce amount of looping looking "banana1*", "banana2*", etc..


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -