Microsoft KB Archive/305342

= A VBA program in Office XP that uses the FileSearch object does not return correct results on a Windows XP-based computer, on a Windows 2000-based computer, or on a Windows Millennium Edition-based computer =

Article ID: 305342

Article Last Modified on 12/4/2007

-

APPLIES TO


 * Microsoft Office XP Professional Edition
 * Microsoft Office XP Small Business Edition
 * Microsoft Office XP Standard Edition
 * Microsoft Office XP Standard Edition for Students and Teachers
 * Microsoft Office XP Developer Edition

-



This article was previously published under Q305342



SYMPTOMS
Consider the following scenario.
 * 1) You use a Microsoft Windows XP computer, 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 .  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 = &quot;.htm&quot; .LookIn = &quot;c:\&quot; .Execute MsgBox .FoundFiles.Count End With End Sub



CAUSE
The issue occurs in Windows 2000 or Windows XP 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:

Method 1: 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 &quot;Symptoms&quot; section, you can change the. search string format that was used in the VBA code to the *. 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 = &quot;*.htm&quot; .LookIn = &quot;c:\&quot; .Execute MsgBox .FoundFiles.Count End With End Sub



STATUS
Microsoft has confirmed that this is a problem in Office XP.

Additional query words: OFFXP

Keywords: kbvba kbbug kbdtacode kbnofix KB305342

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.