Microsoft KB Archive/173818

= PRJ98: Run-time Error if ReplaceAll Argument Set to True =

Article ID: 173818

Article Last Modified on 1/20/2007

-

APPLIES TO


 * Microsoft Project 98 Standard Edition

-



This article was previously published under Q173818



SYMPTOMS
In Microsoft Project 98, when you run a Microsoft Visual Basic for Applications sub procedure (or macro) that contains the Replace method with the ReplaceAll argument set to true, you will receive the following error message after the replacements are made:

Run-time error '1004':

Microsoft Project has finished searching the  field.

 replacements were made.

where  is the name of the field you searched and  is the number of replacements made.

Even though you receive this error, the Replace method is carried out correctly.



CAUSE
This error occurs when you set the ReplaceAll argument to True. In contrast, if you set the ReplaceAll argument to the default value (False) or, if you do not use the ReplaceAll argument, you will not receive the error message. Note that if you do not set the ReplaceAll argument to True, only the first character or characters will be replaced when you run the macro.



WORKAROUND
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. To work around this problem and suppress the run-time error, add the following line of code before the Replace method: On Error Resume Next For example, the following macro replaces all the Name fields that contain the value of T with value of P.  Sub Macro1 On Error Resume Next Replace Field:="Name", Test:="contains", Value:="T", _ Replacement:="P",ReplaceAll:=True End Sub For more information about the Replace method, click the Office Assistant, type Replace, click Search, and then click "Replace Method."

NOTE: If the Assistant is hidden, click the Office Assistant button on the Standard Toolbar. If Visual Basic help is not installed on your computer, please see the following article in the Microsoft Knowledge base:

120802 Office: How to Add/Remove a Single Office Program or Component



STATUS
Microsoft has confirmed this to be a problem in the versions of Microsoft Project listed at the beginning of this article. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

Additional query words: vba

Keywords: kbbug kbdtacode kbmacro kbpending KB173818

-

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

© Microsoft Corporation. All rights reserved.