Count files in diectory

J

Jim Edwards

Hello,
Kind of new to VBA in Word, but I have an opportunity to use it.
I want to know if it is possible to count the number of files in a
directory. My ultimate goal is to save a file as <filenametext??> where the
"??" is the filenumber count + 1. If that is too hard I can just add a
msgbox with the next file name and have the user save the file manually.
The need for this macro is to help users save a copy of a protected document
in the proper directory with the proper name. My plan is to write a
procedure that would fire automatically when the user tries to type onto a
protected document.
Thanks,
Jim
 
M

Malcolm Smith

Jim

You have two choices; the first is to use the Dir$() command which is well
documented in the Help or you can use the FileSystemObject which is within
the Scripting library.

The latter may not be available as there is always discussions on other
groups about the security aspect of this library.

However, the Dir$() function works and works well.

- Malc
www.dragondrop.com
 
W

Word Heretic

G'day "Jim Edwards" <[email protected]>,

yes it is. Do a DIR command with a parm of the directory name. Keep
dir'ing until its blank, counting each instance.

Jim Edwards said:
Hello,
Kind of new to VBA in Word, but I have an opportunity to use it.
I want to know if it is possible to count the number of files in a
directory. My ultimate goal is to save a file as <filenametext??> where the
"??" is the filenumber count + 1. If that is too hard I can just add a
msgbox with the next file name and have the user save the file manually.
The need for this macro is to help users save a copy of a protected document
in the proper directory with the proper name. My plan is to write a
procedure that would fire automatically when the user tries to type onto a
protected document.
Thanks,
Jim

Steve Hudson

Word Heretic, Sydney, Australia
Tricky stuff with Word or words for you.
wordheretic.com

If my answers r 2 terse, ask again or hassle an MVP,
at least they get recognition for it then.
Lengthy replies offlist require payment.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top