DeleteLines 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 DeleteLines method to delete the odd-numbered lines. Although it seems that the second loop should simply delete every other line, note that after each deletion the lines get renumbered. Therefore the deletion is advancing by two lines at each step, one line because I is increasing by one and another line because the larger line numbers are each decreasing by one.

For I = 1 to 26
   Application.VBE.SelectedVBComponent.CodeModule.InsertLines i, Mid$("abcdefghijklmnopqrstuvwxyz", 1, I)
Next
For I = 1 to 13
   Application.VBE.SelectedVBComponent.CodeModule.DeleteLines I
Next