Results 1 to 4 of 4

Thread: [RESOLVED] Editing word documents while keeping the original text.

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2009
    Posts
    10

    Resolved [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!

  2. #2
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,959

    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:
    1. oDoc.Range.Text = codes(j, 1) & " " & codes(j, 2)

    Rate People That Helped You
    Mark Thread Resolved When Resolved

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2009
    Posts
    10

    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..

  4. #4

    Thread Starter
    New Member
    Join Date
    Apr 2009
    Posts
    10

    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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width