Click here to Skip to main content
14,929,864 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello All,
I am stuck at one point where i am opening Microsoft application from C# program and then it writes small paragraph to word from C# and then person has to edit a bit manually in paragraph and leaves cursor anywhere in that paragraph and then C# program again writes paragraph but this time C# doesn't know about the position of cursor because it would be somewhere in middle of paragraph or anywhere in from C# i need to know the position of cursor and move it to last character of that document. i know it's possible but i don't know how to..
If any of you know how to solve this. Please Reply here.

Thanks and Best Regards,

Go to Word - record a macro that does what you want - maybe edit what gets recorded to tidy it up.

Install and reference the relevant version of the Office / Word primary interop assemblies if you haven't done so already.

Copy the recorded macro to your VB code (or edit it to do the same in C#) - maybe some further editing might be needed, but hopefully not much - the VBA macros that get recorded are normally (in my experience) very close to what's needed in VB if you use the PIAs because both translate into / wrap the same COM objects.
mohit`12 6-May-11 9:23am
I Exactly do not know how word does that job otherwise i would have recorded MACRO.there's sure some function or piece of code in c#/C++/VB that does this job easily just need to findout what is it.. thx
NuttingCDEF 6-May-11 12:48pm
Start the macro recorder - go to Word - hit Ctrl-End - Stop recorder - look at the code it's recorded.
mohit`12 9-May-11 10:57am
yeah i found out how recording macro works but word doesn't do that job with their own functionality so i had to write a small piece of code for that function. Hittign END key takes cursor to end of that paragraph in my case i will have 1000 page and user will be editing any page but when user receives new data it has to go at the last line: P anyways thx i got to learn something new frm you ..
NuttingCDEF 9-May-11 18:10pm
Which version of Word are you using? In every (Windows) version I've used, Ctrl-End takes you to the end of the document. End to end of line. Shift-Down to end of paragraph.
object oMissing = System.Reflection.Missing.Value;
object oEoF = WdUnits.wdStory;
wordApp.ActiveWindow.Selection.EndKey(ref oEoF, ref oMissing);
mohit`12 9-May-11 10:55am
awesome works like charm thx alot..and another question if u know when i open word app from c# it hides under my c# application/form. any way to call that window on top or onfront...
thanks alot..
try hooking the keyboard avaliable in codeproject, search for windows hooks
Selection.EndKey Unit:=wdStory
Selection.TypeText Text:=""
phil.o 30-Sep-15 2:45am
Not C#. Moreover, what is the point to answer an already answered 4-years old question?
goodyboy 23-Mar-16 1:43am
point is .... if somebody stuck in the same situation. so they can find answer here....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900