Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 318
Default Count files in a folder

Hello

Is there a way to count how many files are there in a folder? thanks
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 49
Default Count files in a folder

in vb, you can use filesearch in excel up to 2003 vers, lookup that keyword
in help and i think one of the examples does it

in 2007 filesearch has been abandoned and you have to use dir, again the
examples in help contain an appropriate example, but with dir you have to
loop through each file using a counter x=x+1 so x ends up as the result

in both cases you can use wildcars too, so you could count the no of xls files

I have some code but not on me

somone else will no doubt beat me to it!

cheers

"Wanna Learn" wrote:

Hello

Is there a way to count how many files are there in a folder? thanks

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Count files in a folder

Option Explicit
Sub testme()
Dim myFolderName As String
Dim FSO As Object

Set FSO = CreateObject("Scripting.FileSystemObject")
myFolderName = "C:\My Documents\excel"

If FSO.folderexists(myFolderName) Then
MsgBox FSO.getfolder(myFolderName).Files.Count
Else
MsgBox "no folder!"
End If

End Sub

Wanna Learn wrote:

Hello

Is there a way to count how many files are there in a folder? thanks


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 318
Default Count files in a folder

Thanks Dave

Do I copy this macro to any document in the folder? Thanks

"Dave Peterson" wrote:

Option Explicit
Sub testme()
Dim myFolderName As String
Dim FSO As Object

Set FSO = CreateObject("Scripting.FileSystemObject")
myFolderName = "C:\My Documents\excel"

If FSO.folderexists(myFolderName) Then
MsgBox FSO.getfolder(myFolderName).Files.Count
Else
MsgBox "no folder!"
End If

End Sub

Wanna Learn wrote:

Hello

Is there a way to count how many files are there in a folder? thanks


--

Dave Peterson

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Count files in a folder

If it's something that you do lots of times, then I would think that it would
only belong in a single workbook.

I saved this from a previous post:

In fact, lots of people put this kind of routine in a workbook named
personal.xls (or .xla or .xlsm or ...).

Then they store this macro workbook in their XLStart folder. Then each time you
open excel, excel will open this workbook. In fact, they usually hide this
workbook (window|Hide in xl2003 menus), then close excel so that they can save
the workbook in that hidden state.

Then you can hit alt-f8 (to see the run macro dialog) to run your macro.

If you plan on sharing your code with others, then don't use the personal.*
name. Since excel can only open one workbook with that name at a time, you'll
be making your users decide which utilities they really need.

Instead, you can name your utility macro workbook:
LostGuyUtils.xls

It can still go into your XLStart folder and the macros will be available all
the time.

If you decide to create an addin, you'll notice that the procedures aren't
visible in the alt-f8 dialog.

Instead, I'd create an addin and tell the users to open the addin when they need
the macro.

So you'll have to give the users a way to run the macros.

For additions to the worksheet menu bar, I really like the way John Walkenbach
does it in his menumaker workbook:
http://j-walk.com/ss/excel/tips/tip53.htm

Here's how I do it when I want a toolbar:
http://www.contextures.com/xlToolbar02.html
(from Debra Dalgleish's site)

And if you use xl2007:

If you want to learn about modifying the ribbon, you can start at Ron de Bruin's
site:
http://www.rondebruin.nl/ribbon.htm
http://www.rondebruin.nl/qat.htm -- For macros for all workbooks (saved as an
addin)
or
http://www.rondebruin.nl/2007addin.htm

In xl2007, those toolbars and menu modifications will show up under the addins.

Wanna Learn wrote:

Thanks Dave

Do I copy this macro to any document in the folder? Thanks

"Dave Peterson" wrote:

Option Explicit
Sub testme()
Dim myFolderName As String
Dim FSO As Object

Set FSO = CreateObject("Scripting.FileSystemObject")
myFolderName = "C:\My Documents\excel"

If FSO.folderexists(myFolderName) Then
MsgBox FSO.getfolder(myFolderName).Files.Count
Else
MsgBox "no folder!"
End If

End Sub

Wanna Learn wrote:

Hello

Is there a way to count how many files are there in a folder? thanks


--

Dave Peterson


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Check Folder For Files Dave Excel Discussion (Misc queries) 6 November 20th 07 11:16 PM
Hyperlink files same folder only? dahljam Excel Discussion (Misc queries) 2 July 3rd 07 07:00 PM
Copying all files in a folder to new folder michaelberrier Excel Discussion (Misc queries) 2 June 20th 06 05:35 AM
how can I specific a folder with wildcard criteria and excel will import all the correct files in that folder? Raven Excel Discussion (Misc queries) 1 January 24th 06 03:28 PM
SUM in random files in the folder - VBA Marina Limeira Charts and Charting in Excel 0 January 17th 06 01:19 PM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"