kingraw
04-20-2011, 05:22 PM
BEGINNING OF DOC----
TEXTTEXTTEXTTEXT TEXT
HGL;TEXTTEXTTEXT TEXT
TEXTTEXTTEXTTEXT TXT
TEXTTEXTTEXTTEXT TEXT
HGL;TEXTTEXTTEXT TEXT
TEXTTEXTTEXTTEXT TXT
TEXTTEXTTEXTTEXT TEXT
HGL;TEXTTEXTTEXT TEXT
TEXTTEXTTEXTTEXT TXT
END OF DOC------
RESULT DESIRED BY CODE—
BEGINNING OF DOC------
TEXTTEXTTEXTTEXT TEXT
HGL;TEXTTEXTTEXT TEXT
INSERTED TEXT
TEXTTEXTTEXTTEXT TXT
TEXTTEXTTEXTTEXT TEXT
HGL;TEXTTEXTTEXT TEXT
INSERTED TEXT
TEXTTEXTTEXTTEXT TXT
TEXTTEXTTEXTTEXT TEXT
HGL;TEXTTEXTTEXT TEXT
INSERTED TEXT
TEXTTEXTTEXTTEXT TXT
END OF DOC------
This is what I have so far.
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
Set objDoc = objWord.Documents.Open("U:\whereverthe.doc")
Set objSelection = objWord.Selection
objSelection.Find.Forward = True
objSelection.Find.Text = "HGL;"
objSelection.Find.Execute
Do While True
objSelection.Find.Execute
If objSelection.Find.Found Then
objSelection.TypeText(Chr(11))
objSelection.TypeText "INSERTED TEXT "
Else
Exit Do
End If
Loop
Problem is I get it to find the Line where an HGL; is but I can get it to the cursor to the end of the line and I cant use Selection.EndKey Unit:=wdLine cause it keeps giving me an error.
So can someone give me an alternative method to moving the cursor to the end of the line without selecting or highlight the rest of the text so I can do a lean shift+enter to make a new line and insert text.
Sorry for the Length of my post. I just wanted to be clear also to clarify.
The program needs to Find every line that has a HGL; on it and create a new line under it(without disturbing the text on the line the HGL; is on or that underneath it) and a insert new text message.
I'm doing this inside a word doc. Code being ran inside a notepad with the ext. .vbs simple and plain.
Thanks in Advance
TEXTTEXTTEXTTEXT TEXT
HGL;TEXTTEXTTEXT TEXT
TEXTTEXTTEXTTEXT TXT
TEXTTEXTTEXTTEXT TEXT
HGL;TEXTTEXTTEXT TEXT
TEXTTEXTTEXTTEXT TXT
TEXTTEXTTEXTTEXT TEXT
HGL;TEXTTEXTTEXT TEXT
TEXTTEXTTEXTTEXT TXT
END OF DOC------
RESULT DESIRED BY CODE—
BEGINNING OF DOC------
TEXTTEXTTEXTTEXT TEXT
HGL;TEXTTEXTTEXT TEXT
INSERTED TEXT
TEXTTEXTTEXTTEXT TXT
TEXTTEXTTEXTTEXT TEXT
HGL;TEXTTEXTTEXT TEXT
INSERTED TEXT
TEXTTEXTTEXTTEXT TXT
TEXTTEXTTEXTTEXT TEXT
HGL;TEXTTEXTTEXT TEXT
INSERTED TEXT
TEXTTEXTTEXTTEXT TXT
END OF DOC------
This is what I have so far.
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
Set objDoc = objWord.Documents.Open("U:\whereverthe.doc")
Set objSelection = objWord.Selection
objSelection.Find.Forward = True
objSelection.Find.Text = "HGL;"
objSelection.Find.Execute
Do While True
objSelection.Find.Execute
If objSelection.Find.Found Then
objSelection.TypeText(Chr(11))
objSelection.TypeText "INSERTED TEXT "
Else
Exit Do
End If
Loop
Problem is I get it to find the Line where an HGL; is but I can get it to the cursor to the end of the line and I cant use Selection.EndKey Unit:=wdLine cause it keeps giving me an error.
So can someone give me an alternative method to moving the cursor to the end of the line without selecting or highlight the rest of the text so I can do a lean shift+enter to make a new line and insert text.
Sorry for the Length of my post. I just wanted to be clear also to clarify.
The program needs to Find every line that has a HGL; on it and create a new line under it(without disturbing the text on the line the HGL; is on or that underneath it) and a insert new text message.
I'm doing this inside a word doc. Code being ran inside a notepad with the ext. .vbs simple and plain.
Thanks in Advance