FindandReplace(doc, "#ContractNo#", Contract) Word.Application oWord = new Word.Application() others might stumble onto this also and need it in C#. I stumbled onto this post and since I needed it in C# aswell I've translated it to C#. MyStoryRange = myStoryRange.NextStoryRange If myStoryRange.StoryType Thenĭo While Not (myStoryRange.NextStoryRange Is Nothing) 'Now search all other stories using Ranges 'First search the main document using the Selection Sub FindandReplace(ByVal doc As Word.Document, ByVal Findtext As String, ByVal Replacetext As String) Execute(Replace:=.WdReplace.wdReplaceAll)Īny ideas much appreciated, been struggling with this all afternoon!įinally got it sorted this morning, with a bit of help from google, word doesnt seem to iterate through textboxes when doing a find and replace function so you need to iterate through all the storyranges, fortunately this bit of code now works for me!įindandReplace(doc, "#ContractNo#", Contract) I'm trying to create a function to replace fields in a word document using asp.net. The fields are marked in the document using #field# and I need to replace them with the data from the DB. The code I have works fineįor the body of the word document but doesn't appear to work if the text is contained within a textbox, is there a way to correct this?ĭim myStoryRange As .Range
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |