| View previous topic :: View next topic |
| Author |
Message |
David Andersen
Joined: 15 Jul 2005 Posts: 85 Location: Denmark
|
Posted: Sat May 17, 2008 3:47 pm Post subject: COM [SOLVED] |
|
|
I have spent two hours researching, and I cannot get an answer to this. Would it be possible to get the text from a Word document that a user has opened without the user noticing it. It may sound like I am creating a virus or something, but the reason why I need this is that it would enable implementing a feature where several users could collaborate on a Word document in real-time just like collaboration works on Google Docs. This means that if one user makes one keystroke, which changes the document this keystroke is immediately sent to the other users document. If this can be done in Word, it should also be possible in Excel.
As you may understand it is not an option to send "Control+A" to select all and "Control+C" to copy to clipboard for every keystroke that is pushed.
I do not want to use macros as it would seem highly unprofessional that the AHK script would add a macro to a document before collaboration can be enabled.
Last edited by David Andersen on Sat May 17, 2008 9:37 pm; edited 1 time in total |
|
| Back to top |
|
 |
System Monitor
Joined: 09 Mar 2007 Posts: 392 Location: Unknown
|
|
| Back to top |
|
 |
David Andersen
Joined: 15 Jul 2005 Posts: 85 Location: Denmark
|
Posted: Sat May 17, 2008 6:41 pm Post subject: |
|
|
Hi System Monitor,
Thanks for the link. So I understand that using the COM interface is not suitable for this... I will keep looking then, this would be a VERY useful feature. |
|
| Back to top |
|
 |
n-l-i-d Guest
|
|
| Back to top |
|
 |
SomeGuy
Joined: 21 Apr 2008 Posts: 96 Location: somewhere
|
Posted: Sat May 17, 2008 7:53 pm Post subject: |
|
|
Was checking it out......here is some snippets that should get you on your way........
Requires COM.ahk
| Code: | ;Open New Word
Word := com_CreateObject("Word.Application")
com_invoke(Word,"Visible=",True)
com_release(Word)
|
| Code: | ;Open doc in new window
MyDocument := "c:\blah.doc"
Word := com_CreateObject("Word.Application")
com_invoke(Word,"Visible=",True)
Docs := com_invoke(Word,"Documents")
com_invoke(Docs,"Open",MyDocument)
com_release(Docs)
com_release(Word)
|
| Code: | ;Insert Text Into An already open Document
sometext=
(
Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah
Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah
)
Word := COM_GetActiveObject("Word.Application")
Selection := com_invoke(Word,"Selection")
com_invoke(Selection,"TypeText", sometext)
com_release(Selection)
com_release(Word)
|
| Code: | ;Get Text from already open document
Word := COM_GetActiveObject("Word.Application")
ActiveDocument := com_invoke(Word,"ActiveDocument")
Range := com_invoke(ActiveDocument,"Range")
DocText := com_invoke(Range,"Text")
com_release(Range)
com_release(ActiveDocument)
com_release(Word)
|
| Code: | ;Get Selected Text from already open document
Word := COM_GetActiveObject("Word.Application")
Selection := com_invoke(Word,"Selection")
MsgBox % SelText := com_invoke(Selection,"Text")
com_release(Selection)
com_release(Word)
|
|
|
| Back to top |
|
 |
System Monitor
Joined: 09 Mar 2007 Posts: 392 Location: Unknown
|
|
| Back to top |
|
 |
SomeGuy
Joined: 21 Apr 2008 Posts: 96 Location: somewhere
|
Posted: Sat May 17, 2008 8:51 pm Post subject: |
|
|
| yeah we're one and the same |
|
| Back to top |
|
 |
David Andersen
Joined: 15 Jul 2005 Posts: 85 Location: Denmark
|
Posted: Sat May 17, 2008 9:36 pm Post subject: |
|
|
EXCELLENT SomeGuy!
It worked like a charm. For reference for others, this is the working code just copy and paste and it works using windows key+b and windows key+m:
| Code: |
#include COM.ahk
COM_Init()
#b::
{
Word := COM_GetActiveObject("Word.Application")
ActiveDocument := com_invoke(Word,"ActiveDocument")
Range := com_invoke(ActiveDocument,"Range")
DocText := com_invoke(Range,"Text")
com_release(Range)
com_release(ActiveDocument)
com_release(Word)
msgbox, %DocText%
return
}
#m::
{
Word := COM_GetActiveObject("Word.Application")
Selection := com_invoke(Word,"Selection")
MsgBox % SelText := com_invoke(Selection,"Text")
com_release(Selection)
com_release(Word)
return
}
|
Last edited by David Andersen on Sat May 17, 2008 11:59 pm; edited 1 time in total |
|
| Back to top |
|
 |
n-l-i-d Guest
|
|
| Back to top |
|
 |
|