ReplaceLine 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