[RESOLVED] Editing word documents while keeping the original text.
Hello.
This problem is giving me a headache. I know its nooby. But how else will i learn?
Code:
Public objword As New Word.Application
objword.Documents.Open(FileName:=ofilename)
^ Showing the declaration of the word document that i wish to edit.
Code:
Dim oDoc As Word.Document
objword.Visible = True
oDoc = objword.ActiveDocument
oDoc.Range.Text = codes(j, 1) & " " & codes(j, 2)
This gets the document and adds text into it, exactly what i want it to do. But it replaces the whole document. I just want it to add text at the start of the document. Not replace the whole document.
Thanks, Schoolproject.
If there is any needed information. Don't hesitate to ask!
Re: Editing word documents while keeping the original text.
You don't define any range... So the range will be all the document.
VB.NET Code:
oDoc.Range.Text = codes(j, 1) & " " & codes(j, 2)
Re: Editing word documents while keeping the original text.
Yes thank you that did work, but when determining the range it deletes some characters from the beginning of the document.
For example, (this was my result in the word document)
Bill Smith COLLEGE
ADAMS STREET
....
Whereas i want it to say:
Bill Smith MATER DEI CATHOLIC COLLEGE
ADAMS STREET
.....
Its like typing when you have pressed the insert button or something..
Re: Editing word documents while keeping the original text.
Wait thank you it worked after a bit of fiddling!
What finally worked was what you said thank you.
Code:
oDoc.Range(0, 0).Text = codes(j, 1) & " " & codes(j, 2)
Placing the range as 0,0 made it be placed at the beginning without taking any other text out.
Once again thank you.
School project