Friday 15 January 2010

vba - Excel Macro to search folders and return files containing specific keyword and most recent version -


I'm looking for some help in writing a macro that is a folder in my computer for viewing in any file The folder will find a specified keyword, then return the file name, path and the last modified date to an Excel worksheet.

  REF folderPath REF fileName Final Codified FilePath Apple C: \ Fruit Carpet C: \ Vegetables Spinach C: \ Subgues   

For example (see above) ,

I will have keywords and folder paths in column A and B. A named file "Apple_v5.xls" in the folder named "Fruit", so I would like to search the macro for the keyword "Apple", then return the name, latest version and file path (Colonel D, E, F) in the same spreadsheet. Colonel C will only list those keywords in the AL macro again going down the list of keywords until it will reach the end.

It is that I have been in the internet since the research, but it did not work for some reason please help! Thanks!

  Private command command button 1_Click () as DDIP worksheet, RNG as RNG, LRG Long, FPAD = Sheets ("Sheet 2") as string set lstRw = sh.Cells (Find: = "*", later: = sh.Range ("A1"), LookAt: = xlPart, LookIn: = xlFormulas, SearchOrder: = xlByRows, Search Direction: = xl Previous, Match CAS: = False ). Set rng = sh.Range ("A2: A" and LCRR) I = 1 to 100 fpath = Sheets ("Sheet2"). Range ("B" & amp; i) If right (fPath, 1) & lt; & Gt; "\" Then fpath = fPath & amp; "\" End if FWB = Dir (FPS and "*. *") X = 2 while FWB & lt; & Gt; "" RCG INSAT (LCES (FWB), LCE (C. value)) in each C gt; 0 then worksheet ("sheet2"). Set the range ("C" and X) = FWB set fs = CreateObject ("Scripting.FileSystem Object") f = fs.GetFile (fWb) worksheets ("Sheet2"). Range ("E" ("E-2" encoder: "worksheet" ("Sheet 2"). Hyperlink Add Anchor: = Worksheet ("Sheet2"). Room (X, 2), Address: = F. Path column ("A: D"). Autofit set FS = nothing set F = nothing x = x + 1 end if next fWb = set the dot loop sh = nothing set rng = nothing next I can say sheets ( "Sheet 2"). Active End Sub    

with some code / layout here Some problems are essential for you Without rewriting the macro macro, this method can be used by you.

--- Get the range of cells that are your keywords (you already have your rng )

--- Set your line counter (you are already using the x variable to do this)

- - In the Loop category through each cell (you are already using R code for each C in the code)

Then in that loop ...

--- Get the file path from the B column (you already do this when setting your fpath variable )

--- Find the folder for the first file with the keyword using the following code

  fwb = Dir (fpath and c.value & ". * ")   

This takes your reference value and inserts it into the directory path. * *". * "It says that you want to return it to any file type (such as. Apple.txt, Apple.pdf, Apple.mp3)

- If the file is found, populate the date last time Modified, path, file name, and hyperlink (all of which you know how to do the rest, as is done by the rest of the code as well)

- Reset your file and filesystemboat variable ( f and fs )

Finally, outside of your loop, you have your other variable (i.e. sh , rng ) Hope this helps.

No comments:

Post a Comment