Jump to content

prob with _WordDocGetCollection


Recommended Posts

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
Link to comment
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.

Link to comment
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...

Link to comment
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,"")
Link to comment
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

Link to comment
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.

Link to comment
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

Link to comment
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)

Link to comment
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

Link to comment
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...

Link to comment
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)
Link to comment
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)

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...