ReplaceLine Method

Applies To

CodeModule object.

Description

Replaces an existing line of code with a specified line of code.

Syntax

object.ReplaceLine(line, code)

The ReplaceLine syntax has these parts:

Part

Description

object

Required. An object expression that evaluates to an object in the Applies To list.

line

Required. A Long specifying the location of the line you want to replace.

code

Required. A String containing the code you want to insert.


See Also

CountOfDeclarationLines property, CountOfLines property, CountOfVisibleLines property, CreateEventProc method, DeleteLines method, InsertLines method.

Example

The following example has two steps. The first For…Next loop uses the InsertLines method to insert into CodePanes(1) 26 ever-longer initial segments of the alphabet, starting with "a." The last line inserted is the entire alphabet.

The second For…Next loop uses the ReplaceLine method to replace each even-numbered line with the last letter in the string that previously occupied that line. Odd-numbered lines are unchanged.

For I = 1 to 26
    Application.VBE.CodePanes(1).CodeModule.InsertLines I, Mid$("abcdefghijklmnopqrstuvwxyz", 1, I)
Next I
For I = 1 to 13
    Application.VBE.CodePanes(1).CodeModule.ReplaceLine 2*I, Mid$("abcdefghijklmnopqrstuvwxyz", 1, I)
Next I