Count files

I

IztokZ

Part of my Word macro is using for counting files in a folder. The problem is
that result of counting also includes all open files in that folder. So the
number of files is correct only if no documents are open in that folder.

This worked well in Office 2000 (Word 2000). Result didn't include open files.

The macro is the same and it doesn't work correctly in Office 2003 (Word
2003).

The code:

Dim stevec As Integer

With Application.FileSearch
.FileName = "pr????.doc"
.LookIn = "\\_server_\_folder_\"
.SearchSubFolders = False
.Execute
For stevec = 1 To .FoundFiles.Count
Next
End With
MsgBox Stevec


Regards, Iztok
 
R

Russ

Iztok,
Part of my Word macro is using for counting files in a folder. The problem is
that result of counting also includes all open files in that folder. So the
number of files is correct only if no documents are open in that folder.

I might argue that .FileSearch *should* find all files in a folder, whether
they are currently open in Word or not.
This worked well in Office 2000 (Word 2000). Result didn't include open files.

The macro is the same and it doesn't work correctly in Office 2003 (Word
2003).

The code:

Dim stevec As Integer

With Application.FileSearch
.FileName = "pr????.doc"
.LookIn = "\\_server_\_folder_\"
.SearchSubFolders = False
.Execute
For stevec = 1 To .FoundFiles.Count
Next
End With
MsgBox Stevec


Regards, Iztok

This code, I think, will check if any wildcard filenames are currently open
in Word from that folder and, if so, alter the count of files :

Dim MySearchPath As String
Dim Stevec As Long
Dim aDoc As Document
Dim MySearchName As String

MySearchPath = "\\_server_\_folder_\"
MySearchName = "pr????.doc"
With Application.FileSearch
.fileName = MySearchName
.LookIn = MySearchPath
.SearchSubFolders = False
.Execute
Stevec = .FoundFiles.Count
End With
For Each aDoc In Documents
If aDoc.FullName Like MySearchPath & MySearchName Then
Stevec = Stevec - 1
End If
Next aDoc
MsgBox Stevec
 

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