Populate an array with file names
Hi Jacob, this works well,
I've put this sub into the workbook_open area. how can i get a vlookup function to search the array and return the file name ie =VLOOKUP(B4726,arrfiles(),1,true) where arrfiles is the dim array and B4726 is one of the files names? regards Wayne "Jacob Skaria" wrote: Try Sub FilesWithinFolder() Dim strFile As String, strFolder As String Dim intFileCount As Integer, arrFiles As Variant ReDim arrFiles(0) strFolder = "d:\" strFile = Dir(strFolder & "*.*", vbNormal) Do While strFile < "" ReDim Preserve arrFiles(intFileCount) arrFiles(intFileCount) = strFile intFileCount = intFileCount + 1 strFile = Dir Loop MsgBox intFileCount & " file(s) stored to array" End Sub -- Jacob "Wayne" wrote: Sorry, new to programming... Please be gentle I need to populate an array with file names and their extension from a specific directory. ie \\sim7\drawings\200\M - as the directory then populate with: 001.dwg 002.tif 003.dgn 004.dwg Etc, for how ever long the directory is. Any advice? regards Wayne |
Populate an array with file names
Oops, should read;
Dim arrfiles As Range Dim strVal As String Set arrfiles = Range("MyTableRange") strVal = Application.VLookup(Range("B4726"), arrfiles, 1) "ozgrid.com" wrote in message ... Something like; Dim arrfiles As Range Dim strVal As String Set arrfiles = Range("MyTableRange") arrfiles = Application.VLookup(Range("B4726"), arrfiles, 1, True) -- Regards Dave Hawley www.ozgrid.com "Wayne" wrote in message ... Hi Jacob, this works well, I've put this sub into the workbook_open area. how can i get a vlookup function to search the array and return the file name ie =VLOOKUP(B4726,arrfiles(),1,true) where arrfiles is the dim array and B4726 is one of the files names? regards Wayne "Jacob Skaria" wrote: Try Sub FilesWithinFolder() Dim strFile As String, strFolder As String Dim intFileCount As Integer, arrFiles As Variant ReDim arrFiles(0) strFolder = "d:\" strFile = Dir(strFolder & "*.*", vbNormal) Do While strFile < "" ReDim Preserve arrFiles(intFileCount) arrFiles(intFileCount) = strFile intFileCount = intFileCount + 1 strFile = Dir Loop MsgBox intFileCount & " file(s) stored to array" End Sub -- Jacob "Wayne" wrote: Sorry, new to programming... Please be gentle I need to populate an array with file names and their extension from a specific directory. ie \\sim7\drawings\200\M - as the directory then populate with: 001.dwg 002.tif 003.dgn 004.dwg Etc, for how ever long the directory is. Any advice? regards Wayne |
Populate an array with file names
Oops, should read;
Dim arrfiles As Range Dim strVal As String Set arrfiles = Range("MyTableRange") strVal = Application.VLookup(Range("B4726"), arrfiles, 1) "ozgrid.com" wrote in message ... Something like; Dim arrfiles As Range Dim strVal As String Set arrfiles = Range("MyTableRange") arrfiles = Application.VLookup(Range("B4726"), arrfiles, 1, True) -- Regards Dave Hawley www.ozgrid.com "Wayne" wrote in message ... Hi Jacob, this works well, I've put this sub into the workbook_open area. how can i get a vlookup function to search the array and return the file name ie =VLOOKUP(B4726,arrfiles(),1,true) where arrfiles is the dim array and B4726 is one of the files names? regards Wayne "Jacob Skaria" wrote: Try Sub FilesWithinFolder() Dim strFile As String, strFolder As String Dim intFileCount As Integer, arrFiles As Variant ReDim arrFiles(0) strFolder = "d:\" strFile = Dir(strFolder & "*.*", vbNormal) Do While strFile < "" ReDim Preserve arrFiles(intFileCount) arrFiles(intFileCount) = strFile intFileCount = intFileCount + 1 strFile = Dir Loop MsgBox intFileCount & " file(s) stored to array" End Sub -- Jacob "Wayne" wrote: Sorry, new to programming... Please be gentle I need to populate an array with file names and their extension from a specific directory. ie \\sim7\drawings\200\M - as the directory then populate with: 001.dwg 002.tif 003.dgn 004.dwg Etc, for how ever long the directory is. Any advice? regards Wayne |
All times are GMT +1. The time now is 03:51 AM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com