Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 64
Default Checking the number of files in a folder using VBA

Hi all,

The following code saves the active spreadsheet into subfolders within
c:/inbox.

sPath = ActiveWorkbook.FullName
ActiveWorkbook.SaveAs "c:\Inbox\" & _
Range("C12") & "\" & ActiveWorkbook.Name

Kill sPath
ActiveWorkbook.Close

I want to write a piece of code that brings up a message when the specified
subfolder holds 15 files already, stating that this subfolder is 'fill up'
and to save the file in the next subfolder.

Is there any way that VBA can test this? I spoke to my lecturer and he said
there are sub-routines available to do this, but I have drawn a blank with my
research.


Any help would be much appreciated,

Thanks,

Bhupinder Rayat

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 400
Default Checking the number of files in a folder using VBA

You can get the count of files in a folder as follows:

Function xx()
Set fso = CreateObject("Scripting.FileSystemObject")
xx = fso.getfolder("c:\ajay").Files.Count
Set fso = Nothing
End Function


"Bhupinder Rayat" wrote:

Hi all,

The following code saves the active spreadsheet into subfolders within
c:/inbox.

sPath = ActiveWorkbook.FullName
ActiveWorkbook.SaveAs "c:\Inbox\" & _
Range("C12") & "\" & ActiveWorkbook.Name

Kill sPath
ActiveWorkbook.Close

I want to write a piece of code that brings up a message when the specified
subfolder holds 15 files already, stating that this subfolder is 'fill up'
and to save the file in the next subfolder.

Is there any way that VBA can test this? I spoke to my lecturer and he said
there are sub-routines available to do this, but I have drawn a blank with my
research.


Any help would be much appreciated,

Thanks,

Bhupinder Rayat

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Checking the number of files in a folder using VBA

On easy way is to use the scripting runtime library.

Sub Tester1()
Dim fso As Object
Dim fldr As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set fldr = fso.GetFolder("C:\BlueBook")
Debug.Print fldr.Files.Count
End Sub

The above used late binding. If you want to use early binding, you can
create a reference to the scripting runtime in Tools=References in the VBE.

Then you can do:

Sub Tester2()
Dim fso As New FileSystemObject
Dim fldr As Folder
Set fldr = fso.GetFolder("C:\BlueBook")
Debug.Print fldr.Files.Count
End Sub

--
Regards,
Tom Ogilvy

"Bhupinder Rayat" wrote in
message ...
Hi all,

The following code saves the active spreadsheet into subfolders within
c:/inbox.

sPath = ActiveWorkbook.FullName
ActiveWorkbook.SaveAs "c:\Inbox\" & _
Range("C12") & "\" & ActiveWorkbook.Name

Kill sPath
ActiveWorkbook.Close

I want to write a piece of code that brings up a message when the

specified
subfolder holds 15 files already, stating that this subfolder is 'fill up'
and to save the file in the next subfolder.

Is there any way that VBA can test this? I spoke to my lecturer and he

said
there are sub-routines available to do this, but I have drawn a blank with

my
research.


Any help would be much appreciated,

Thanks,

Bhupinder Rayat



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 64
Default Checking the number of files in a folder using VBA

Thanks Guys, that works great.

How can I get the result of the count to be displayed in a cell on a
spreadsheet?

I can then use that cell ref (or name range) to generate a message to say
the specified sub folder is full up.

Thanks again,


Bhupinder Rayat

"Tom Ogilvy" wrote:

On easy way is to use the scripting runtime library.

Sub Tester1()
Dim fso As Object
Dim fldr As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set fldr = fso.GetFolder("C:\BlueBook")
Debug.Print fldr.Files.Count
End Sub

The above used late binding. If you want to use early binding, you can
create a reference to the scripting runtime in Tools=References in the VBE.

Then you can do:

Sub Tester2()
Dim fso As New FileSystemObject
Dim fldr As Folder
Set fldr = fso.GetFolder("C:\BlueBook")
Debug.Print fldr.Files.Count
End Sub

--
Regards,
Tom Ogilvy

"Bhupinder Rayat" wrote in
message ...
Hi all,

The following code saves the active spreadsheet into subfolders within
c:/inbox.

sPath = ActiveWorkbook.FullName
ActiveWorkbook.SaveAs "c:\Inbox\" & _
Range("C12") & "\" & ActiveWorkbook.Name

Kill sPath
ActiveWorkbook.Close

I want to write a piece of code that brings up a message when the

specified
subfolder holds 15 files already, stating that this subfolder is 'fill up'
and to save the file in the next subfolder.

Is there any way that VBA can test this? I spoke to my lecturer and he

said
there are sub-routines available to do this, but I have drawn a blank with

my
research.


Any help would be much appreciated,

Thanks,

Bhupinder Rayat




  #5   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Checking the number of files in a folder using VBA

hi,
range("A1").value = fldr
or
Cells(1,1).vaue = fldr

-----Original Message-----
Thanks Guys, that works great.

How can I get the result of the count to be displayed in

a cell on a
spreadsheet?

I can then use that cell ref (or name range) to generate

a message to say
the specified sub folder is full up.

Thanks again,


Bhupinder Rayat

"Tom Ogilvy" wrote:

On easy way is to use the scripting runtime library.

Sub Tester1()
Dim fso As Object
Dim fldr As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set fldr = fso.GetFolder("C:\BlueBook")
Debug.Print fldr.Files.Count
End Sub

The above used late binding. If you want to use early

binding, you can
create a reference to the scripting runtime in

Tools=References in the VBE.

Then you can do:

Sub Tester2()
Dim fso As New FileSystemObject
Dim fldr As Folder
Set fldr = fso.GetFolder("C:\BlueBook")
Debug.Print fldr.Files.Count
End Sub

--
Regards,
Tom Ogilvy

"Bhupinder Rayat"

wrote in
message news:A46A085C-7922-4C17-8490-

...
Hi all,

The following code saves the active spreadsheet into

subfolders within
c:/inbox.

sPath = ActiveWorkbook.FullName
ActiveWorkbook.SaveAs "c:\Inbox\" & _
Range("C12") & "\" & ActiveWorkbook.Name

Kill sPath
ActiveWorkbook.Close

I want to write a piece of code that brings up a

message when the
specified
subfolder holds 15 files already, stating that this

subfolder is 'fill up'
and to save the file in the next subfolder.

Is there any way that VBA can test this? I spoke to

my lecturer and he
said
there are sub-routines available to do this, but I

have drawn a blank with
my
research.


Any help would be much appreciated,

Thanks,

Bhupinder Rayat




.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 64
Default Checking the number of files in a folder using VBA

Hi,

i was looking for Cells(1, 1).Value = fldr.Files.Count, but ur code got me
on the right track.


Thanks.

" wrote:

hi,
range("A1").value = fldr
or
Cells(1,1).vaue = fldr

-----Original Message-----
Thanks Guys, that works great.

How can I get the result of the count to be displayed in

a cell on a
spreadsheet?

I can then use that cell ref (or name range) to generate

a message to say
the specified sub folder is full up.

Thanks again,


Bhupinder Rayat

"Tom Ogilvy" wrote:

On easy way is to use the scripting runtime library.

Sub Tester1()
Dim fso As Object
Dim fldr As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set fldr = fso.GetFolder("C:\BlueBook")
Debug.Print fldr.Files.Count
End Sub

The above used late binding. If you want to use early

binding, you can
create a reference to the scripting runtime in

Tools=References in the VBE.

Then you can do:

Sub Tester2()
Dim fso As New FileSystemObject
Dim fldr As Folder
Set fldr = fso.GetFolder("C:\BlueBook")
Debug.Print fldr.Files.Count
End Sub

--
Regards,
Tom Ogilvy

"Bhupinder Rayat"

wrote in
message news:A46A085C-7922-4C17-8490-

...
Hi all,

The following code saves the active spreadsheet into

subfolders within
c:/inbox.

sPath = ActiveWorkbook.FullName
ActiveWorkbook.SaveAs "c:\Inbox\" & _
Range("C12") & "\" & ActiveWorkbook.Name

Kill sPath
ActiveWorkbook.Close

I want to write a piece of code that brings up a

message when the
specified
subfolder holds 15 files already, stating that this

subfolder is 'fill up'
and to save the file in the next subfolder.

Is there any way that VBA can test this? I spoke to

my lecturer and he
said
there are sub-routines available to do this, but I

have drawn a blank with
my
research.


Any help would be much appreciated,

Thanks,

Bhupinder Rayat




.


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
Pulling pdf files from general folder to specific folder [email protected] Excel Discussion (Misc queries) 2 September 8th 09 09:41 PM
Path and Number of files in a folder. - Pass to Macro. Richard Excel Discussion (Misc queries) 1 December 21st 06 09:20 PM
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
Checking for the Existence of a Folder Viswanath Tumu Excel Programming 2 April 19th 04 08:31 AM
Checking to see if Folder exists Dan[_25_] Excel Programming 2 September 24th 03 02:42 AM


All times are GMT +1. The time now is 09:45 AM.

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

About Us

"It's about Microsoft Excel"