Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Check if a pre0defined number of workbooks exist in a specific directory
I am trying to merge several excel workbooks but before running my code
I want to check if all required workbooks exist in a directory. The master document consists of 3 sheets. Each sheet has employee names in the first row, starting at column D. The number of employees can vary (the last employee will be the one just before the column with the name "TOTAL". Each name followed by .xls is a workbook that should be present in the directory. The code checks if these files exist in the directory. If they all exist and there are no other files present, the code will execute; if they are not all present or other files exist, code should stop running, displaying a message that xxxx is missing or an unknown xxxx files has been found in the directory. Thanks in advance. Mark |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Check if a pre0defined number of workbooks exist in a specific dir
Something along the lines of this untested pseudo code:
Dim list() as String Dim sPath as string, sName as String Redim list(1 to 1) Dim bFound as Boolean, i as Long, j as Long Dim sMsg as String, bMissing as Boolean Dim bAdditional as Boolean, sh as Object bMissing = False sMsg = "Missing: " & vbCrLF sPath = "C:\Temp\" sname = dir(sPath & "*.xls") do while sName < "" list(ubound(list)) = lcase(sName) Redim Preserve list(1 to Ubound(list) + 1) sName = dir Loop redim preserved List(1 to Ubound(list)-1) for each sh in Workbooks("Master.xls").Worksheets i = 4 do while instr(1,sh.cells(1,i),"total",vbTextcompare) = 0 bFound = False for j = 1 to ubound(list) if lcase(sh.cells(1,j).Value) & ".xls" = list(j) then bFound = True list(j) = "" exit for end if Next j Loop if not bFound then smsg = sMsg & sh.cells(1,i) & vbCrLf bMissing = True end if i = i + 1 Next sh sMsg1 = "Other files: " & vbCrLf for j = 1 to Ubound(list) if len(trim(list)) 0 then sMsg1 = sMsg1 & List(j) & vbCrLf bAdditional = True end if Next if bAddtional then sMsg = sMsg & vbCr & sMsg1 end if if bAdditional or bMissing then msgbox sMsg exit sub End if -- Regards, Tom Ogilvy "Ixtreme" wrote: I am trying to merge several excel workbooks but before running my code I want to check if all required workbooks exist in a directory. The master document consists of 3 sheets. Each sheet has employee names in the first row, starting at column D. The number of employees can vary (the last employee will be the one just before the column with the name "TOTAL". Each name followed by .xls is a workbook that should be present in the directory. The code checks if these files exist in the directory. If they all exist and there are no other files present, the code will execute; if they are not all present or other files exist, code should stop running, displaying a message that xxxx is missing or an unknown xxxx files has been found in the directory. Thanks in advance. Mark |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Check for a tab if it is exist | Excel Discussion (Misc queries) | |||
Check if a value exist in a column | Excel Worksheet Functions | |||
Save to directory and create if not exist | Excel Programming | |||
How to check if a folder/directory exist using VBA | Excel Programming | |||
Check if directory empty OR no of files in directory. | Excel Programming |