---
title: "Find specific text and replace with Image file in MS Word"  
description: "Find specific text and replace with Image file in MS Word"  
author: "Nirav Parikh"  
published: 2013-05-09  
updated: 2013-05-09  
canonical: https://www.mindstick.com/forum/851/find-specific-text-and-replace-with-image-file-in-ms-word  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Find specific text and replace with Image file in MS Word

Hi,\
\

My MS [word file](https://www.mindstick.com/forum/159152/how-can-i-find-and-replace-text-in-docx-microsoft-word-file-using-interop) shown like below [format](https://www.mindstick.com/forum/162083/how-to-convert-ost-files-into-pst-format)

#A# #B# #C# #D# #E#

I have implemented below [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) to replace text in [MS word](https://www.mindstick.com/forum/23166/preview-ms-word-excel-powerpoint-document-in-browser) file using C#.

```
public void ReplaceWordDoc(){object missing = Missing.Value;Document doc = Globals.ThisAddIn.Application.ActiveDocument;List search = GetSearchList();foreach (var searchItem in search){foreach (Range tmpRange in ((Document)doc).StoryRanges){tmpRange.Find.ClearFormatting();tmpRange.Find.Text = searchItem.Find;tmpRange.Find.Replacement.ClearFormatting();tmpRange.Find.Replacement.Text = searchItem.Replace;object replaceAll = WdReplace.wdReplaceAll;if (searchItem.Replace.Contains(“gif”)){tmpRange.InlineShapes.AddPicture(searchItem.Replace, Type.Missing, Type.Missing, tmpRange);}else{tmpRange.Find.Execute(ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,ref missing, ref missing, ref missing, ref replaceAll, ref missing, ref missing, ref missing, ref missing);}}}}private List GetSearchList(){List ilst = new List();for (int i = 0; i <= 4; i++){ReplacerSearch ObjReplacerSearch = new ReplacerSearch();if (i == 0){ObjReplacerSearch.Find = "#A#";ObjReplacerSearch.Replace = "ABCD";}else if (i == 1){ObjReplacerSearch.Find = "#B#";ObjReplacerSearch.Replace = "EFGH";}else if (i == 2){ObjReplacerSearch.Find = "#C#";ObjReplacerSearch.Replace = "IJKL";}else if (i == 3){ObjReplacerSearch.Find = "#D#";ObjReplacerSearch.Replace = "MVC Developer";}else if (i == 4){ObjReplacerSearch.Find = "#E#";ObjReplacerSearch.Replace = "D:\\ajax_loader.gif";}ilst.Add(ObjReplacerSearch);}return ilst;}
```

My MS word out [put](https://answers.mindstick.com/qa/111890/can-you-explain-the-difference-between-put-and-post-http-methods) is like,

[Image File] #ABCD# #EFGH# #IJKL# #[MVC](https://www.mindstick.com/forum/155803/define-cache-profile-in-mvc) [Developer](https://www.mindstick.com/articles/157260/variation-between-web-designer-and-web-developer)# #E#

I need image at place of #E# not on the start.

or refer below [link](https://www.mindstick.com/articles/23633/link-builder),

[http://stackoverflow.com/questions/16456792/find-specific-text-and-replace-with-image-file-in-ms-word](http://stackoverflow.com/questions/16456792/find-specific-text-and-replace-with-image-file-in-ms-word)

\
\
Thanks,\
Nirav


---

Original Source: https://www.mindstick.com/forum/851/find-specific-text-and-replace-with-image-file-in-ms-word

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
