Click here to Skip to main content
Rate this: bad
good
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 document.so 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,
Mohit.
Posted 5-May-11 10:53am
Rate this: bad
good
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.
  Permalink  
Comments
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
good
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);
  Permalink  
Comments
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
good
Please Sign up or sign in to vote.

Solution 3

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

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

  Print Answers RSS
0 OriginalGriff 7,903
1 Sergey Alexandrovich Kryukov 7,142
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,820


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 9 May 2011
Copyright © CodeProject, 1999-2014
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