PC Review


Reply
Thread Tools Rate Thread

Create file list

 
 
Gert-Jan
Guest
Posts: n/a
 
      19th Nov 2006
Hi,

Can someone help me with the following:

I want a macro that creates a file list (starting in Sheet1, A1) of all
excel-files in a specific directory. But: the file itself (test.xls) should
not appear in that list and also not the names of the files wich have the
same name as one of the sheets in test.xls.
For example: if there is a workbook "apple.xls" AND test.xls contains a
sheet called "apple", apple.xls should not appear in the filelist. If apple
is NOT one of the sheetnames, apple.xls must be showed in the list.

Any help would be appriciated.

Gert-Jan



 
Reply With Quote
 
 
 
 
Helmut Weber
Guest
Posts: n/a
 
      19th Nov 2006
Hi Gert-Jan,

well, you got to compare the names of the
workbooks in the folder with the name
of the active workbook and, if unequal
to the name of the active workbook, with
the names of the worksheets in the active workbook.

What code have you got so far?


--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"

 
Reply With Quote
 
Don Guillett
Guest
Posts: n/a
 
      19th Nov 2006
This will list the files. Suggest doing this first and then another for/each
loop macro with FINDNEXT to remove the undesired entries.

Here is one you can adapt using DIR

Sub anotherfindfiles()
Application.ScreenUpdating = False
Dim FN As String ' For File Name
Dim ThisRow As Long
Dim MediaFileLocation As String
MediaFileLocation = "c:\YOURFOLDER\*.YOURFILEEXTENSION"
FN = Dir(MediaFileLocation)
Do Until FN = ""
ThisRow = ThisRow + 1
Cells(ThisRow, 1) = FN
FN = Dir
Loop
Application.ScreenUpdating = True
End Sub


--
Don Guillett
SalesAid Software
(E-Mail Removed)
"Gert-Jan" <(E-Mail Removed)> wrote in message
news:4560bdb3$0$28046$(E-Mail Removed)...
> Hi,
>
> Can someone help me with the following:
>
> I want a macro that creates a file list (starting in Sheet1, A1) of all
> excel-files in a specific directory. But: the file itself (test.xls)
> should not appear in that list and also not the names of the files wich
> have the same name as one of the sheets in test.xls.
> For example: if there is a workbook "apple.xls" AND test.xls contains a
> sheet called "apple", apple.xls should not appear in the filelist. If
> apple is NOT one of the sheetnames, apple.xls must be showed in the list.
>
> Any help would be appriciated.
>
> Gert-Jan
>
>
>



 
Reply With Quote
 
Tom Ogilvy
Guest
Posts: n/a
 
      19th Nov 2006
Sub ListFiles()
Dim sPath as String, sName as STring
Dim sName1 as String, bFound as Boolean
Dim i as Long, sh as Worksheet
sPath = Thisworkbook.Path
if right(sPath,1) <> "\" then sPath = sPath & "\"
sName = Dir(sPath & "*.xls")
do while sName <> ""
sName1 = Left(sName,len(sName)-4)
if lcase(sName) <> lcase(ThisWorkbook.Name) then
bFound = False
for each sh in Thisworkbook.Worksheets
if lcase(sName1) = lcase(sh.name) then
bfound = True
exit for
end if
Next
if not bFound then
i = i + 1
with worksheets("Sheet1")
.Cells(i,1) = sName
end with
end if
end if
sName = Dir
Loop
End Sub

Untested pseudo code should get you started.

--
Regards,
Tom Ogilvy

"Gert-Jan" <(E-Mail Removed)> wrote in message
news:4560bdb3$0$28046$(E-Mail Removed)...
> Hi,
>
> Can someone help me with the following:
>
> I want a macro that creates a file list (starting in Sheet1, A1) of all
> excel-files in a specific directory. But: the file itself (test.xls)
> should not appear in that list and also not the names of the files wich
> have the same name as one of the sheets in test.xls.
> For example: if there is a workbook "apple.xls" AND test.xls contains a
> sheet called "apple", apple.xls should not appear in the filelist. If
> apple is NOT one of the sheetnames, apple.xls must be showed in the list.
>
> Any help would be appriciated.
>
> Gert-Jan
>
>
>



 
Reply With Quote
 
Gert-Jan
Guest
Posts: n/a
 
      19th Nov 2006
Hi Don, thanks, but your solution doesn't work. I found this (history this
group), but I don't know how to change the last line: the message box should
not appear, data must be in list. Hope somone could help.

Sub AllExcelFilesInFolder()
Dim FileList() As String
Dim Counter As Long
Dim NextFile As String
Dim DirToSearch As String

DirToSearch = "C:\Exceldok" 'the folder name
Counter = 0


NextFile = Dir(DirToSearch & "\" & "*.xls")


Do Until NextFile = ""
ReDim Preserve FileList(Counter)
FileList(Counter) = DirToSearch & "\" & NextFile
Counter = Counter + 1
NextFile = Dir()
Loop


For Counter = LBound(FileList) To UBound(FileList)
MsgBox FileList(Counter)
'do your stuff here instead of previous line
Next
End Sub





"Don Guillett" <(E-Mail Removed)> schreef in bericht
news:(E-Mail Removed)...
> This will list the files. Suggest doing this first and then another
> for/each loop macro with FINDNEXT to remove the undesired entries.
>
> Here is one you can adapt using DIR
>
> Sub anotherfindfiles()
> Application.ScreenUpdating = False
> Dim FN As String ' For File Name
> Dim ThisRow As Long
> Dim MediaFileLocation As String
> MediaFileLocation = "c:\YOURFOLDER\*.YOURFILEEXTENSION"
> FN = Dir(MediaFileLocation)
> Do Until FN = ""
> ThisRow = ThisRow + 1
> Cells(ThisRow, 1) = FN
> FN = Dir
> Loop
> Application.ScreenUpdating = True
> End Sub
>
>
> --
> Don Guillett
> SalesAid Software
> (E-Mail Removed)
> "Gert-Jan" <(E-Mail Removed)> wrote in message
> news:4560bdb3$0$28046$(E-Mail Removed)...
>> Hi,
>>
>> Can someone help me with the following:
>>
>> I want a macro that creates a file list (starting in Sheet1, A1) of all
>> excel-files in a specific directory. But: the file itself (test.xls)
>> should not appear in that list and also not the names of the files wich
>> have the same name as one of the sheets in test.xls.
>> For example: if there is a workbook "apple.xls" AND test.xls contains a
>> sheet called "apple", apple.xls should not appear in the filelist. If
>> apple is NOT one of the sheetnames, apple.xls must be showed in the list.
>>
>> Any help would be appriciated.
>>
>> Gert-Jan
>>
>>
>>

>
>



 
Reply With Quote
 
Gert-Jan
Guest
Posts: n/a
 
      19th Nov 2006
Thanks Tom, this works fine!

Regards, Gert-Jan

"Tom Ogilvy" <(E-Mail Removed)> schreef in bericht
news:(E-Mail Removed)...
> Sub ListFiles()
> Dim sPath as String, sName as STring
> Dim sName1 as String, bFound as Boolean
> Dim i as Long, sh as Worksheet
> sPath = Thisworkbook.Path
> if right(sPath,1) <> "\" then sPath = sPath & "\"
> sName = Dir(sPath & "*.xls")
> do while sName <> ""
> sName1 = Left(sName,len(sName)-4)
> if lcase(sName) <> lcase(ThisWorkbook.Name) then
> bFound = False
> for each sh in Thisworkbook.Worksheets
> if lcase(sName1) = lcase(sh.name) then
> bfound = True
> exit for
> end if
> Next
> if not bFound then
> i = i + 1
> with worksheets("Sheet1")
> .Cells(i,1) = sName
> end with
> end if
> end if
> sName = Dir
> Loop
> End Sub
>
> Untested pseudo code should get you started.
>
> --
> Regards,
> Tom Ogilvy
>
> "Gert-Jan" <(E-Mail Removed)> wrote in message
> news:4560bdb3$0$28046$(E-Mail Removed)...
>> Hi,
>>
>> Can someone help me with the following:
>>
>> I want a macro that creates a file list (starting in Sheet1, A1) of all
>> excel-files in a specific directory. But: the file itself (test.xls)
>> should not appear in that list and also not the names of the files wich
>> have the same name as one of the sheets in test.xls.
>> For example: if there is a workbook "apple.xls" AND test.xls contains a
>> sheet called "apple", apple.xls should not appear in the filelist. If
>> apple is NOT one of the sheetnames, apple.xls must be showed in the list.
>>
>> Any help would be appriciated.
>>
>> Gert-Jan
>>
>>
>>

>
>



 
Reply With Quote
 
=?Utf-8?B?ZnVnYXppNDg=?=
Guest
Posts: n/a
 
      21st Nov 2006
The only problem with Don's code was that ThisRow was never defined. Once it
is defined, the code creates a list of file names. Good job, Don. i will
probably use this elsewhere.

"Gert-Jan" wrote:

> Hi Don, thanks, but your solution doesn't work. I found this (history this
> group), but I don't know how to change the last line: the message box should
> not appear, data must be in list. Hope somone could help.
>
> Sub AllExcelFilesInFolder()
> Dim FileList() As String
> Dim Counter As Long
> Dim NextFile As String
> Dim DirToSearch As String
>
> DirToSearch = "C:\Exceldok" 'the folder name
> Counter = 0
>
>
> NextFile = Dir(DirToSearch & "\" & "*.xls")
>
>
> Do Until NextFile = ""
> ReDim Preserve FileList(Counter)
> FileList(Counter) = DirToSearch & "\" & NextFile
> Counter = Counter + 1
> NextFile = Dir()
> Loop
>
>
> For Counter = LBound(FileList) To UBound(FileList)
> MsgBox FileList(Counter)
> 'do your stuff here instead of previous line
> Next
> End Sub
>
>
>
>
>
> "Don Guillett" <(E-Mail Removed)> schreef in bericht
> news:(E-Mail Removed)...
> > This will list the files. Suggest doing this first and then another
> > for/each loop macro with FINDNEXT to remove the undesired entries.
> >
> > Here is one you can adapt using DIR
> >
> > Sub anotherfindfiles()
> > Application.ScreenUpdating = False
> > Dim FN As String ' For File Name
> > Dim ThisRow As Long
> > Dim MediaFileLocation As String
> > MediaFileLocation = "c:\YOURFOLDER\*.YOURFILEEXTENSION"
> > FN = Dir(MediaFileLocation)
> > Do Until FN = ""
> > ThisRow = ThisRow + 1
> > Cells(ThisRow, 1) = FN
> > FN = Dir
> > Loop
> > Application.ScreenUpdating = True
> > End Sub
> >
> >
> > --
> > Don Guillett
> > SalesAid Software
> > (E-Mail Removed)
> > "Gert-Jan" <(E-Mail Removed)> wrote in message
> > news:4560bdb3$0$28046$(E-Mail Removed)...
> >> Hi,
> >>
> >> Can someone help me with the following:
> >>
> >> I want a macro that creates a file list (starting in Sheet1, A1) of all
> >> excel-files in a specific directory. But: the file itself (test.xls)
> >> should not appear in that list and also not the names of the files wich
> >> have the same name as one of the sheets in test.xls.
> >> For example: if there is a workbook "apple.xls" AND test.xls contains a
> >> sheet called "apple", apple.xls should not appear in the filelist. If
> >> apple is NOT one of the sheetnames, apple.xls must be showed in the list.
> >>
> >> Any help would be appriciated.
> >>
> >> Gert-Jan
> >>
> >>
> >>

> >
> >

>
>
>

 
Reply With Quote
 
Don Guillett
Guest
Posts: n/a
 
      21st Nov 2006
I just re-tested as presented and it worked just fine

--
Don Guillett
SalesAid Software
(E-Mail Removed)
"fugazi48" <(E-Mail Removed)> wrote in message
news:EB75BF7C-7C31-42C8-8721-(E-Mail Removed)...
> The only problem with Don's code was that ThisRow was never defined. Once
> it
> is defined, the code creates a list of file names. Good job, Don. i will
> probably use this elsewhere.
>
> "Gert-Jan" wrote:
>
>> Hi Don, thanks, but your solution doesn't work. I found this (history
>> this
>> group), but I don't know how to change the last line: the message box
>> should
>> not appear, data must be in list. Hope somone could help.
>>
>> Sub AllExcelFilesInFolder()
>> Dim FileList() As String
>> Dim Counter As Long
>> Dim NextFile As String
>> Dim DirToSearch As String
>>
>> DirToSearch = "C:\Exceldok" 'the folder name
>> Counter = 0
>>
>>
>> NextFile = Dir(DirToSearch & "\" & "*.xls")
>>
>>
>> Do Until NextFile = ""
>> ReDim Preserve FileList(Counter)
>> FileList(Counter) = DirToSearch & "\" & NextFile
>> Counter = Counter + 1
>> NextFile = Dir()
>> Loop
>>
>>
>> For Counter = LBound(FileList) To UBound(FileList)
>> MsgBox FileList(Counter)
>> 'do your stuff here instead of previous line
>> Next
>> End Sub
>>
>>
>>
>>
>>
>> "Don Guillett" <(E-Mail Removed)> schreef in bericht
>> news:(E-Mail Removed)...
>> > This will list the files. Suggest doing this first and then another
>> > for/each loop macro with FINDNEXT to remove the undesired entries.
>> >
>> > Here is one you can adapt using DIR
>> >
>> > Sub anotherfindfiles()
>> > Application.ScreenUpdating = False
>> > Dim FN As String ' For File Name
>> > Dim ThisRow As Long
>> > Dim MediaFileLocation As String
>> > MediaFileLocation = "c:\YOURFOLDER\*.YOURFILEEXTENSION"
>> > FN = Dir(MediaFileLocation)
>> > Do Until FN = ""
>> > ThisRow = ThisRow + 1
>> > Cells(ThisRow, 1) = FN
>> > FN = Dir
>> > Loop
>> > Application.ScreenUpdating = True
>> > End Sub
>> >
>> >
>> > --
>> > Don Guillett
>> > SalesAid Software
>> > (E-Mail Removed)
>> > "Gert-Jan" <(E-Mail Removed)> wrote in message
>> > news:4560bdb3$0$28046$(E-Mail Removed)...
>> >> Hi,
>> >>
>> >> Can someone help me with the following:
>> >>
>> >> I want a macro that creates a file list (starting in Sheet1, A1) of
>> >> all
>> >> excel-files in a specific directory. But: the file itself (test.xls)
>> >> should not appear in that list and also not the names of the files
>> >> wich
>> >> have the same name as one of the sheets in test.xls.
>> >> For example: if there is a workbook "apple.xls" AND test.xls contains
>> >> a
>> >> sheet called "apple", apple.xls should not appear in the filelist. If
>> >> apple is NOT one of the sheetnames, apple.xls must be showed in the
>> >> list.
>> >>
>> >> Any help would be appriciated.
>> >>
>> >> Gert-Jan
>> >>
>> >>
>> >>
>> >
>> >

>>
>>
>>



 
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
create a file list from a folder? Hal239 Microsoft Excel Misc 2 5th Feb 2009 03:32 PM
How do I create a mail list in a cvs file? =?Utf-8?B?SmVmZmVyeQ==?= Microsoft Access 0 2nd Nov 2007 05:20 PM
Create a new contact list from a text file =?Utf-8?B?SmFuZXQgVw==?= Microsoft Outlook Contacts 1 12th Jun 2006 03:43 PM
Create a Simple List of AD Users to .csv File Niel Bullock Microsoft Windows 2000 Applications 2 28th Apr 2004 06:54 AM
How to create a text file list? medic Windows XP Basics 7 19th Nov 2003 06:11 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:16 PM.