Click here to Skip to main content
15,907,874 members
Home / Discussions / C#
   

C#

 
GeneralRe: Editing Word Pin
Sandeepdshenoy30-Oct-13 21:42
Sandeepdshenoy30-Oct-13 21:42 
Hi,

This is what i have done till now...

C#
var myWord = new Microsoft.Office.Interop.Word.Application();
           var myDoc = new Microsoft.Office.Interop.Word.Document();

           object missing = System.Type.Missing;
           try
           {

               object FileName = @"D:\Declaration.docx";

               myDoc = myWord.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);

               myDoc.Activate();


               foreach (Microsoft.Office.Interop.Word.Range tempRange in myDoc.StoryRanges)
               {
                   tempRange.Find.Text = "@DonorName";
                   tempRange.Find.Replacement.Text = "Sandeep D Shenoy";
                   object replaceAll = Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll;

                   tempRange.Find.Wrap = Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue;


                   tempRange.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);

                   tempRange.Find.Text = "@Date";
                   tempRange.Find.Replacement.Text = "01-01-2013";
                   tempRange.Find.Wrap = Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue;


                   tempRange.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);

                   tempRange.Find.Text = "@Telephone";
                   tempRange.Find.Replacement.Text = "1234567890";
                   tempRange.Find.Wrap = Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue;


                   tempRange.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);

                   tempRange.Find.Text = "@Email";
                   tempRange.Find.Replacement.Text = "abd@gmail.com";

                   tempRange.Find.Wrap = Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue;


                   tempRange.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);
               }

               myDoc.Save();

               // Close the doc and exit the app
               myDoc.Close(ref missing, ref missing, ref missing);
               myWord.Application.Quit(ref missing, ref missing, ref missing);
           }
           catch (Exception ee)
           {
               myDoc.Close(ref missing, ref missing, ref missing);
               myWord.Application.Quit(ref missing, ref missing, ref missing);
           }



I replaced 4 Texts from the document and replaced it with values, but this document has to be reused many times. So is there any way to bypass that ?
AnswerRe: Editing Word Pin
Kenneth Haugland30-Oct-13 21:31
mvaKenneth Haugland30-Oct-13 21:31 
QuestionIssue with Excel vesion in C# Pin
superselector29-Oct-13 19:05
superselector29-Oct-13 19:05 
AnswerRe: Issue with Excel vesion in C# Pin
Mycroft Holmes29-Oct-13 20:11
professionalMycroft Holmes29-Oct-13 20:11 
GeneralRe: Issue with Excel vesion in C# Pin
Kenneth Haugland29-Oct-13 20:30
mvaKenneth Haugland29-Oct-13 20:30 
GeneralRe: Issue with Excel vesion in C# Pin
Mycroft Holmes29-Oct-13 21:16
professionalMycroft Holmes29-Oct-13 21:16 
GeneralRe: Issue with Excel vesion in C# Pin
Kenneth Haugland29-Oct-13 21:25
mvaKenneth Haugland29-Oct-13 21:25 
GeneralRe: Issue with Excel vesion in C# Pin
superselector30-Oct-13 18:42
superselector30-Oct-13 18:42 
AnswerRe: Issue with Excel vesion in C# Pin
Kenneth Haugland30-Oct-13 21:29
mvaKenneth Haugland30-Oct-13 21:29 
AnswerRe: Issue with Excel vesion in C# Pin
Bernhard Hiller29-Oct-13 21:39
Bernhard Hiller29-Oct-13 21:39 
AnswerRe: Issue with Excel vesion in C# Pin
TnTinMn30-Oct-13 14:12
TnTinMn30-Oct-13 14:12 
QuestionNeed pointers to build the Car Park Management System Pin
ashuthind00129-Oct-13 18:53
ashuthind00129-Oct-13 18:53 
AnswerRe: Need pointers to build the Car Park Management System Pin
Mycroft Holmes29-Oct-13 20:07
professionalMycroft Holmes29-Oct-13 20:07 
AnswerRe: Need pointers to build the Car Park Management System Pin
turbosupramk330-Oct-13 1:48
turbosupramk330-Oct-13 1:48 
AnswerRe: Need pointers to build the Car Park Management System Pin
Dave Kreskowiak30-Oct-13 2:54
mveDave Kreskowiak30-Oct-13 2:54 
GeneralRe: Need pointers to build the Car Park Management System Pin
jschell30-Oct-13 8:08
jschell30-Oct-13 8:08 
GeneralRe: Need pointers to build the Car Park Management System Pin
Dave Kreskowiak30-Oct-13 9:04
mveDave Kreskowiak30-Oct-13 9:04 
AnswerRe: Need pointers to build the Car Park Management System Pin
GuyThiebaut31-Oct-13 3:20
professionalGuyThiebaut31-Oct-13 3:20 
QuestionDll Files in .NET Pin
Amit Saini29-Oct-13 18:37
professionalAmit Saini29-Oct-13 18:37 
AnswerRe: Dll Files in .NET Pin
Mycroft Holmes29-Oct-13 20:01
professionalMycroft Holmes29-Oct-13 20:01 
GeneralRe: Dll Files in .NET Pin
Amit Saini31-Oct-13 18:41
professionalAmit Saini31-Oct-13 18:41 
AnswerRe: Dll Files in .NET Pin
Amol_B29-Oct-13 22:24
professionalAmol_B29-Oct-13 22:24 
AnswerRe: Dll Files in .NET Pin
Dave Kreskowiak30-Oct-13 2:37
mveDave Kreskowiak30-Oct-13 2:37 
AnswerRe: Dll Files in .NET Pin
WuRunZhe30-Oct-13 4:13
WuRunZhe30-Oct-13 4:13 
Questionplate recognition help Pin
Member 1023834329-Oct-13 15:47
Member 1023834329-Oct-13 15:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.