Click here to Skip to main content
11,720,324 members (80,438 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# Word Microsoft
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,
Posted 5-May-11 9:53am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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 at 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 at 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 at 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 at 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.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

object oMissing = System.Reflection.Missing.Value;
object oEoF = WdUnits.wdStory;
wordApp.ActiveWindow.Selection.EndKey(ref oEoF, ref oMissing);
mohit`12 at 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..
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

try hooking the keyboard avaliable in codeproject, search for windows hooks

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 2,029
1 OriginalGriff 844
2 F-ES Sitecore 640
3 Maciej Los 609
4 Richard MacCutchan 540

Advertise | Privacy | Mobile
Web01 | 2.8.150901.1 | Last Updated 9 May 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100