AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

COM [SOLVED]

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
David Andersen



Joined: 15 Jul 2005
Posts: 85
Location: Denmark

PostPosted: Sat May 17, 2008 3:47 pm    Post subject: COM [SOLVED] Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
System Monitor



Joined: 09 Mar 2007
Posts: 392
Location: Unknown

PostPosted: Sat May 17, 2008 6:22 pm    Post subject: Reply with quote

I am having a hard time getting anything from Word with ControlGetText, but try reading this http://www.autohotkey.com/forum/viewtopic.php?t=2421&highlight=controlgettext+word
It looks like it has useful information
_________________
Back to top
View user's profile Send private message Visit poster's website
David Andersen



Joined: 15 Jul 2005
Posts: 85
Location: Denmark

PostPosted: Sat May 17, 2008 6:41 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
n-l-i-d
Guest





PostPosted: Sat May 17, 2008 6:48 pm    Post subject: Reply with quote

This is all I could find:

- Here is a bit of code that might be helpful: COM and Word.Application - How do I call "document"

- A related comment by Sean:

Quote:
I think you can access the contents of the documents via Word.Document COM object.


- Here is a posting if you want to learn more about COM in general: [Solved] COM Assistance Request

HTH
Back to top
SomeGuy



Joined: 21 Apr 2008
Posts: 96
Location: somewhere

PostPosted: Sat May 17, 2008 7:53 pm    Post subject: Reply with quote

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
View user's profile Send private message
System Monitor



Joined: 09 Mar 2007
Posts: 392
Location: Unknown

PostPosted: Sat May 17, 2008 8:33 pm    Post subject: Reply with quote

http://www.autohotkey.com/forum/viewtopic.php?t=31923&start=0&postdays=0&postorder=asc&highlight=
Just posted Very Happy
_________________
Back to top
View user's profile Send private message Visit poster's website
SomeGuy



Joined: 21 Apr 2008
Posts: 96
Location: somewhere

PostPosted: Sat May 17, 2008 8:51 pm    Post subject: Reply with quote

yeah we're one and the same
Back to top
View user's profile Send private message
David Andersen



Joined: 15 Jul 2005
Posts: 85
Location: Denmark

PostPosted: Sat May 17, 2008 9:36 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
n-l-i-d
Guest





PostPosted: Sat May 17, 2008 9:50 pm    Post subject: Reply with quote

Two thumbs up! There is also ez_invoke() EZ-COM Wrapper btw. Cool
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group