Hi,
My requirement I need to edit or replace content in the word document every time and save it to another location.
What I wanted is I want to simplify this through vb.net but stuck in somewhere I am doing mistake in the code itself (I am completly newbie).
I have created a form and I have inserted 2 controls i.e. RichTextBox and Button
If I Enter text in Richtextbox like below format word document is generating undesired results.
example:
add1
add2
add3
add4
result: add1 add2 add3 add4 add5
what I want is in what ever way I am giving input in the textbox the same output should be generated in word doc.
below is my faulty code:
Imports System.Runtime.InteropServices
Imports Microsoft.Office.Interop
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim objWordApp As Word.Application
objWordApp = New Word.Application
Dim objDoc As Word.Document
Dim rng As String
'Open an existing document.
objWordApp.Documents.Open("C:\Users\Desktop\Sample.docx")
objDoc = objWordApp.ActiveDocument
'Find and replace some text.
objDoc.Content.Find.Execute(FindText:="<Address>", _
ReplaceWith:=rng, _
Replace:=Word.WdReplace.wdReplaceAll)
'Save and close the document.
objWordApp.Documents.Item(1).Save()
objWordApp.Documents.Close(Word.WdSaveOptions.wdDoNotSaveChanges)
objWordApp.Quit()
objWordApp = Nothing
End Sub
End Class
Thanks for everyone's help. :)