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.
  1. You use a Microsoft Windows 2000-based computer or a Microsoft Windows Millennium Edition-based computer.
  2. You install Microsoft Office XP on your computer.
  3. 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.
  4. 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 Service

Note This method applies only to Windows 2000 only.
  1. Click Start, click Run, type Control.exe in the Open box, and then click OK.
  2. In Control Panel, double-click Administrative Tools, and then double-click Services.
  3. In the right pane, locate and then click Indexing Service.
  4. On the Action menu, click Properties.
  5. On the General tab, click Disabled in the Startup type list, and then click OK to save the changes.
  6. Close the Services window.

Method 2: Change search string format

To 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:MinorLast Reviewed:1/10/2006
Keywords:KbVBA kbbug kbdtacode kbnofix KB305342 kbAudITPRO