|
-
Jun 14th, 2004, 02:39 PM
#1
Thread Starter
New Member
counting documents in windows explorer using VBA
HELP!!! Before I go completely insane....I have a macro that is set up to count the number of files in a folder so if all my files are there it will print the files to a prn file and print the entire batch. However it appears to be counting the files that start with the ~. Is there a way to set it to only count the documents that are not temporary and only .doc files?
Thanks!
Tina
-
Jun 15th, 2004, 02:17 AM
#2
Addicted Member
This will do the job :-
Code:
'------------------------------
Sub test()
Dim MyCount As Integer
Dim MyName As String
MyName = Dir("c:\*.doc")
Do While MyName <> ""
MyCount = MyCount + 1
MyName = Dir
Loop
MsgBox (MyCount)
End Sub
'-------------------------------
Regards
BrianB
-------------------------------
-
Jun 15th, 2004, 09:34 AM
#3
Thread Starter
New Member
Thanks for your response. I tried your code. tweeked it a little because I pass in the path and I come up with 0 even though there are 2 files in there. Here's what it looks like:
Dim MyCount As Integer
Dim MyName As String
MyName = Dir(target & "*.doc")
Do While MyName <> ""
MyCount = MyCount + 1
MyName = Dir
Loop
MsgBox (MyCount)
Here what I was using...
Set fs = CreateObject("Scripting.FileSystemObject")
Set fc = fs.GetFolder(target)
intFileCount = fc.files.Count
This wasn't working, so I tried this...
With Application.FileSearch
.LookIn = (target)
.FileType = msoFileTypeWordDocuments
If .Execute() > 0 Then
intFileCount = .FoundFiles.Count
End If
End With
It appeared to work, but now I have complaints again today...
Help!!!
-
Jun 16th, 2004, 04:13 AM
#4
Originally posted by tgrant29
VB Code:
Dim MyCount As Integer
Dim MyName As String
MyName = Dir(target & "*.doc"[color=red], 63)
Do While MyName <> "" and left(MyName,1)<>"~" and not(MyName="." or MyName="..")[/color]
MyCount = MyCount + 1
MyName = Dir
Loop
MsgBox (MyCount)
The other two methods, dunno 
Prolly FSO would work, but you'd need to read up on methods/properties.
As to Application.FileSearch, it may only find certain filetypes and not all filetypes (it is part of the VBA App...)
Vince
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
-
Jun 16th, 2004, 08:51 AM
#5
Thread Starter
New Member
Thanks Vince! Much appreicated!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|