Don't say you didn't ask! 8>/
Since I posted I was playing, trying to see what I could do, and got this.
This is run on a three-column tab-delimited text file.
Sub TestMe1()
' Created 07-01-03 by Ed Millis
' to separate query into individual Word docs
'
' Sets up the document
' Drop to the end of the document and insert a
' table cell as a marker
<DELETED CODE FOR BREVITY>
<IT WORKED WHEN I STEPPED THROUGH IT>
' Formats the document margins
With ActiveDocument.PageSetup
<DELETED CODE FOR BREVITY>
<IT WORKED WHEN I STEPPED THROUGH IT>
End With
' The first sub deletes empty lines until it hits the
' table cell at the end of the document
Application.Run MacroName:="SubRoutine1"
' Deletes the entire first line of text, the header row
Selection.HomeKey Unit:=wdStory
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
End Sub
This is the Subroutine1:
Sub SubRoutine1()
' Written 07/01/03 by Ed Millis
' Do only if not in a table
Do While Selection.Information(wdWithInTable) = False
' Detects if the cursor is on a valid text entry or an empty line,
' and deletes an empty line
Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
If Selection.Characters.Count < 2 Then
Selection.Delete
Else: Selection.HomeKey Unit:=wdLine
Selection.MoveDown Unit:=wdLine, Count:=1
End If
' If there was not a valid entry, start over
Loop
End Sub
The SubRoutine1 begins at the top of the document and runs down to the table
cell at the end, deleting all empty lines. It works - when run by itself!
When stepping through, however, the Application.Run line is highlighted, the
top line is deleted, and the debugger drops to End Sub. I can't tell if the
top line is deleted because of the SubRoutine1 or the last set of
instructions.
The idea is that right after where I have stopped writing the main sub,
there will be more instructions that will be looped, also with the Do While
Selection.Information(wdWithInTable) = False criteria. I was hoping that,
by enclosing it in a separate macro running within this one, I could loop
without interference. Except the SubRoutine1 apparently won't loop by
itself from within this macro.
Have I successfully confused you?
Ed