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

Re: Count files by Russ

Russ
Mon Jul 10 01:43:08 CDT 2006

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

--
Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID