PC Review


Reply
Thread Tools Rate Thread

Check if a pre0defined number of workbooks exist in a specific directory

 
 
Ixtreme
Guest
Posts: n/a
 
      2nd Jan 2007
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 With Quote
 
 
 
 
=?Utf-8?B?VG9tIE9naWx2eQ==?=
Guest
Posts: n/a
 
      2nd Jan 2007
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 With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Check to see if a specific field exist on form SF Microsoft Access 4 18th Dec 2007 01:55 AM
Check if a predefined number of workbooks exist in a specific directory Ixtreme Microsoft Excel Programming 4 2nd Jan 2007 04:35 PM
Does exist a software that check USB pen insertion for specific files ? Simone Murdock Freeware 12 15th May 2005 10:31 PM
check folder / directory is exist or not... =?Utf-8?B?a2Vsa2Vs?= Microsoft C# .NET 1 15th Jul 2004 05:53 AM
How to check if a folder/directory exist using VBA wellie Microsoft Excel Programming 1 1st Mar 2004 02:24 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:31 AM.