A VBA program in Office XP that uses the FileSearch object does not return correct results on a Windows 2000-based computer or on a Windows Millennium Edition-based computer (305342)
The information in this article applies to:
- Microsoft Office XP Professional
- Microsoft Office XP Small Business
- Microsoft Office XP Standard
- Microsoft Office XP Students and Teachers
- Microsoft Office XP Developer
This article was previously published under Q305342 SYMPTOMS
Consider the following scenario. - You use a Microsoft Windows 2000-based computer or a Microsoft Windows Millennium Edition-based computer.
- You install Microsoft Office XP on your computer.
- You create a Microsoft Visual Basic for Applications (VBA) program in Office XP that uses the FileSearch object to search for files that have a particular file name extension.
- You specify the search criteria string for files in the .FileExtension format in the VBA program.
In this scenario, when you run the VBA program, the FileSearch object does not return the correct results when you search files that have the file name extension that was specified in the VBA code. For example, you may experience this problem when you run a VBA program that contains the following sample VBA code: Sub count_htm_files()
With Application.FileSearch
.FileName = ".htm"
.LookIn = "c:\"
.Execute
MsgBox .FoundFiles.Count
End With
End Sub
CAUSE
The issue occurs in Windows 2000 if Indexing Service is enabled. By default, Indexing Service is enabled in Windows Millennium Edition.
WORKAROUND
To work around this problem, use one of the following methods: Method1: Disable Indexing ServiceNote This method applies only to Windows 2000 only. - Click Start, click Run, type Control.exe in the Open box, and then click OK.
- In Control Panel, double-click Administrative Tools, and then double-click Services.
- In the right pane, locate and then click Indexing Service.
- On the Action menu, click Properties.
- On the General tab, click Disabled in the Startup type list, and then click OK to save the changes.
- Close the Services window.
Method 2: Change search string formatTo avoid the problem that is mentioned in the "Symptoms" section, you can change the . FileExtension search string format that was used in the VBA code to the *. FileExtension format. For example, you may use VBA code that is similar to the following sample VBA code. This code searches for files that are in the *.htm format. Sub count_htm_files()
With Application.FileSearch
.FileName = "*.htm"
.LookIn = "c:\"
.Execute
MsgBox .FoundFiles.Count
End With
End Sub STATUS
Microsoft has confirmed that this is a problem in Office XP.
Modification Type: | Minor | Last Reviewed: | 1/10/2006 |
---|
Keywords: | KbVBA kbbug kbdtacode kbnofix KB305342 kbAudITPRO |
---|
|