Sign in to follow this  
Followers 0
AvidLearner

prob with _WordDocGetCollection

13 posts in this topic

#1 ·  Posted (edited)

CODE
#include<word.au3>

$oWordApp = _WordAttach ($docname, "FileName")

$oDoc = _WordDocGetCollection ($oWordApp, 0)

$oPath = $oDoc.FullName

msgbox(0,$oPath,"")

$docname is known which will be a open document....

I get an error msg saying " Variable must be of type Object "

I tried and could not get the full path of the document.. Plz do help..

Thanx...

Edited by AvidLearner

Share this post


Link to post
Share on other sites



The 0 in the line "_WordDocGetCollection ($oWordApp, 0)" returns the active document, so the following will work:

#include<word.au3>
$oWordApp = _WordAttach ($docname, "FileName")
WinActivate ($docname)
WinWaitActive($docname)
$oDoc = _WordDocGetCollection ($oWordApp, 0)
$oPath = $oDoc.FullName
msgbox(0,$oPath,"")

I'd imagine there are better ways to get the full path though.

Share this post


Link to post
Share on other sites

The 0 in the line "_WordDocGetCollection ($oWordApp, 0)" returns the active document, so the following will work:

#include<word.au3>
$oWordApp = _WordAttach ($docname, "FileName")
WinActivate ($docname)
WinWaitActive($docname)
$oDoc = _WordDocGetCollection ($oWordApp, 0)
$oPath = $oDoc.FullName
msgbox(0,$oPath,"")

I'd imagine there are better ways to get the full path though.

Thank you foster74... :P

Yeah I tried it... but m getting an error saying " Variable must be of type Object "

Could you plz show me an easier way to get d path...

Thnx in advance...

Share this post


Link to post
Share on other sites

Tell me what errors are showing.

#include<word.au3>
$oWordApp = _WordAttach ($docname, "FileName")
ConsoleWrite('_WordAttach Error = ' & @ERROR & @CRLF)
WinActivate ($docname)
WinWaitActive($docname)
$oDoc = _WordDocGetCollection ($oWordApp, 0)
ConsoleWrite('_WordDocGetCollection Error = ' & @ERROR & @CRLF)
$oPath = $oDoc.FullName
msgbox(0,$oPath,"")

Share this post


Link to post
Share on other sites

Tell me what errors are showing.

#include<word.au3>
$oWordApp = _WordAttach ($docname, "FileName")
ConsoleWrite('_WordAttach Error = ' & @ERROR & @CRLF)
WinActivate ($docname)
WinWaitActive($docname)
$oDoc = _WordDocGetCollection ($oWordApp, 0)
ConsoleWrite('_WordDocGetCollection Error = ' & @ERROR & @CRLF)
$oPath = $oDoc.FullName
msgbox(0,$oPath,"")
I got $oPath = 0 from MsgBox command

Earlier I got errors saying

line : -1

Error:variable must be of type object

Share this post


Link to post
Share on other sites

Run the following code:

#include<word.au3>
$oWordApp = _WordAttach ($docname, "FileName")
msgbox(0,'','_WordAttach Error = ' & @ERROR & @CRLF)
WinActivate ($docname)
WinWaitActive($docname)
$oDoc = _WordDocGetCollection ($oWordApp, 0)
msgbox(0,'','_WordDocGetCollection Error = ' & @ERROR & @CRLF)
$oPath = $oDoc.FullName
msgbox(0,$oPath,"")

And tell me what the first two message boxes say.

Share this post


Link to post
Share on other sites

Run the following code:

#include<word.au3>
$oWordApp = _WordAttach ($docname, "FileName")
msgbox(0,'','_WordAttach Error = ' & @ERROR & @CRLF)
WinActivate ($docname)
WinWaitActive($docname)
$oDoc = _WordDocGetCollection ($oWordApp, 0)
msgbox(0,'','_WordDocGetCollection Error = ' & @ERROR & @CRLF)
$oPath = $oDoc.FullName
msgbox(0,$oPath,"")

And tell me what the first two message boxes say.

I got

_wordattach error=7 and

_worddocgetcollection error=3

and sorry fr late reply as server wz down...

Thank you

Share this post


Link to post
Share on other sites

Could you plz help me in finding some other easier and fail proof method to extract its path if possible...

Thank you

Share this post


Link to post
Share on other sites

#include<word.au3>
$docname = 'target.docx'
$oWordApp = _WordAttach ($docname, "FileName")
$oDoc = _WordDocGetCollection ($oWordApp, -1)
For $oDoc in $oDoc
    If Stringinstr($oDoc.FullName, $docname) Then $oPath = $oDoc.FullName 
Next
msgbox(0,'',$oPath)

Share this post


Link to post
Share on other sites

#include<word.au3>
$docname = 'target.docx'
$oWordApp = _WordAttach ($docname, "FileName")
$oDoc = _WordDocGetCollection ($oWordApp, -1)
For $oDoc in $oDoc
    If Stringinstr($oDoc.FullName, $docname) Then $oPath = $oDoc.FullName 
Next
msgbox(0,'',$oPath)

Thanks a lot foster...

Finally it worked... :P

Share this post


Link to post
Share on other sites

CODE
WinwaitActive( "- Microsoft Word" )

$title1 = WinGetTitle( "Microsoft Word" )

$docname = StringTrimRight( $title1 , 17 )

$result = StringInStr( $docname , "compatibility" )

If $result = 0 Then

Else

$docname = StringTrimRight( $docname , 21 )

EndIf

MsgBox(0,$docname,$docname)

$oWordApp = _WordAttach($docname, "FileName")

WinActivate ($docname)

WinWaitActive($docname)

$oDoc = _WordDocGetCollection ($oWordApp, -1)

For $oDoc in $oDoc

If Stringinstr($oDoc.FullName, $docname) Then $oPath = $oDoc.FullName

Next

This code is properly working and giving me back the path of the opened word doc

but

when you remove the msgbox() code from the program,,, its showing an error saying

AutoIT error:

Line : -1

error : variable must be of type "object"

Can you help me out here plz..

Thank you...

Share this post


Link to post
Share on other sites

This script works fine for me even with no msgbox at the end.

#include<word.au3>
Opt("WinTitleMatchMode", 2) 
WinwaitActive( "- Microsoft Word" )
$title1 = WinGetTitle( "Microsoft Word" )
$docname = StringTrimRight( $title1 , 17 )
$result = StringInStr( $docname , "compatibility" )
If $result <> 0 Then $docname = StringTrimRight( $docname , 21 )
$oWordApp = _WordAttach($docname, "FileName")
$oDoc = _WordDocGetCollection ($oWordApp, -1)
For $oDoc in $oDoc
    If Stringinstr($oDoc.FullName, $docname) Then $oPath = $oDoc.FullName
Next
MsgBox(0,$oPath,$oPath)

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

This script works fine for me even with no msgbox at the end.

#include<word.au3>
Opt("WinTitleMatchMode", 2) 
WinwaitActive( "- Microsoft Word" )
$title1 = WinGetTitle( "Microsoft Word" )
$docname = StringTrimRight( $title1 , 17 )
$result = StringInStr( $docname , "compatibility" )
If $result <> 0 Then $docname = StringTrimRight( $docname , 21 )
$oWordApp = _WordAttach($docname, "FileName")
$oDoc = _WordDocGetCollection ($oWordApp, -1)
For $oDoc in $oDoc
    If Stringinstr($oDoc.FullName, $docname) Then $oPath = $oDoc.FullName
Next
MsgBox(0,$oPath,$oPath)

yeah ,, :P

It definitely needs an output @ the end... But it isn't working fr me,, its showing error as stated above only when I remove the MsgBox which is highlighted in the abv code box given by me...

Is thr any problem wid ma OS or autoIT version...?? m using tthe latest Autoit v3 version,,,

Edited by AvidLearner

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0