Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word Macro: Insert Leading Character 1

Status
Not open for further replies.

logius

Programmer
Aug 30, 2001
175
US
I've created a word macro that will insert a character (`) at the beginning of each line in a newly created document. Problem I'm having is that the second line of the document isn't receiving the character.

Here is the code in question:
Code:
    LoopVar = myRange.ComputeStatistics _
                   (wdStatisticParagraphs)

    Selection.HomeKey Unit:=wdStory
    Selection.HomeKey Unit:=wdLine
    Selection.TypeText Text:="`"
    
    For x = 1 To LoopVar
        Selection.MoveDown Unit:=wdLine
        Selection.HomeKey Unit:=wdLine
        Selection.TypeText Text:="`"
   Next x
----------------------------------------
If you are reading this, then you have read too far... :p

lightwarrior@hotmail.com
 
Const Insert_Text = "`"

With Selection
.EndKey Unit:=wdStory

Do
.HomeKey Unit:=wdLine
.TypeText Text:=Insert_Text
.MoveUp Unit:=wdLine
Loop Until .Information(wdFirstCharacterLineNumber) = 1

.HomeKey Unit:=wdLine
.TypeText Text:=Insert_Text
End With

Use a line count and not a paragraph count.

M *<:)
 
Justin, I knew there was a reason you were higher up on the expert list than me. Thanks, it worked like charm. :-D

Mossoft, dunno what to tell you. It didn't work. :-I ----------------------------------------
If you are reading this, then you have read too far... :p

lightwarrior@hotmail.com
 
Daaaaahhh! Spoke too soon. Now it moved to the third line. For some odd reason, changing the LoopVar altered things so that the third line is being skipped now. Why me? ----------------------------------------
If you are reading this, then you have read too far... :p

lightwarrior@hotmail.com
 
Okay, I figured out what is causing the problem. Thanks for your help. ----------------------------------------
If you are reading this, then you have read too far... :p

lightwarrior@hotmail.com
 
dear logius,

and what was the reason?
Just to become more wise ;-)

regards astrid
 
I actually left out some code that was in the routine. The problem was in there. Here is the modified routine that works.
Code:
    For x = 1 To LoopVar
        Selection.TypeText Text:=&quot;`&quot;
        If Resident = 0 Then
            Selection.HomeKey Unit:=wdLine
            Selection.MoveUntil Cset:=&quot; &quot;, Count:=10
            Selection.TypeText Text:=&quot;,&quot;
            Selection.TypeText Text:=&quot;&quot;&quot;&quot;
            Selection.EndKey Unit:=wdLine
            Selection.TypeText Text:=&quot;&quot;&quot;&quot;
        End If
        Selection.MoveDown Unit:=wdLine
        Selection.HomeKey Unit:=wdLine
  Next x
If you know Word macros, then you know that the Count tells the cursor how the max number of spaces to check for the Cset value. Well, I had initiallly set the number so high (30) that it was going to the next line and searching for the character (only in cases where there was a single word on the line and no spaces). Since the cursor would move to the next line, the code above that point had no effect. ----------------------------------------
If you are reading this, then you have read too far... :p

lightwarrior@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top