ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Find and Replace string in Word Document using C# and VB.Net in Windows Application<p>Hi&nbsp;PRA,</p> <p>You can't correct all the statement. Only you can replace&nbsp;Д and&nbsp;Б in the sentences. Can't add the .(dot) after the number of each question.</p> <p>For this you need to write custom code.</p> <p>Refer below code to replace the&nbsp;Д and&nbsp;Б.</p> <p><strong><span style="text-decoration: underline;">Namespace</span></strong></p> <p><strong>C#</strong></p> <pre class="brush: csharp">using Word = Microsoft.Office.Interop.Word;</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Imports Word = Microsoft.Office.Interop.Word</pre> <p><strong><span style="text-decoration: underline;">Code</span></strong></p> <p><strong>C#</strong></p> <pre class="brush: csharp">private void button1_Click(object sender, EventArgs e) { object fileName = @&#34;D:\Test.docx&#34;; Word.Application word = new Word.Application(); Word.Document doc = new Word.Document(); object missing = System.Type.Missing; try { doc = word.Documents.Open(ref fileName, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing); doc.Activate(); foreach (Word.Range docRange in doc.StoryRanges) { docRange.Text = docRange.Text.Replace(&#34;$Д)&#34;, &#34;$D)&#34;).Replace(&#34;$Б)&#34;, &#34;$B)&#34;); } doc.Save(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { ((Word._Document)doc).Close(); ((Word._Application)word).Quit(); } }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) Dim fileName As Object = &#34;D:\Test.docx&#34; Dim word As Word.Application = New Word.Application() Dim doc As Word.Document = New Word.Document() Dim missing As Object = System.Type.Missing Try doc = word.Documents.Open(fileName, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing) doc.Activate() For Each docRange As Word.Range In doc.StoryRanges docRange.Text = docRange.Text.Replace(&#34;$Д)&#34;, &#34;$D)&#34;).Replace(&#34;$Б)&#34;, &#34;$B)&#34;) Next doc.Save() Catch ex As Exception MessageBox.Show(ex.Message) Finally (CType(doc, Word._Document)).Close() (CType(word, Word._Application)).Quit() End Try End Sub</pre> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/741160/Find-and-Replace-string-in-Word-Document-using-C-and-VBNet-in-Windows-Application/https://www.aspforums.net:443/Threads/741160/Find-and-Replace-string-in-Word-Document-using-C-and-VBNet-in-Windows-Application/Mon, 31 Dec 2018 07:08:30 GMT