Hello,
I am trying to iterate through all texts in a document (paragraphs, tables, header-footer, table of contents, textboxs), and translate them and replace the texts with the translated texts. I don't want to search and replace.
I tried some codes, they worked for some documents but in a document like in the picture below, the texts are coming word by word, and word by word translation doesn't mean any thing, I have to find to whole paragraph and replace the whole text with the translated text without loosing the format. How can I write a code to fully cover all situations?
Thanks,
Sub ReplaceText4() Using doc As WordprocessingDocument = WordprocessingDocument.Open(ListBox1.Items(0), True) Dim document = doc.MainDocumentPart.Document For Each Text2 In document.Descendants(Of Text)() ' <<< Here 'If Text2.Text.Contains("text-to-replace") Then Text2.Text = Text2.Text.Replace(Text2.Text, "My New Text") 'End If Next End Using End Sub