Sign in to follow this  
Followers 0
AvidLearner

Error : Variable must be of type object

12 posts in this topic

When I run my script, it gives an error saying

variable must be of type object in the _wordattach code line

CODE
#Include<file.au3>

#include<string.au3>

#include<word.au3>

#include <WindowsConstants.au3>

AutoItSetOption( "trayiconhide",1 )

AutoItSetOption( "wintitlematchmode",2 )

AutoItSetOption( "sendkeydelay",1 )

AutoItSetOption( "WinTextMatchMode",1 )

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

If $result = 0 Then

$docname = _StringInsert( ".docx",$docname,-5 )

Else

$docname = _StringInsert( ".doc",$docname,-4 )

EndIf

$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



Pls do help me ....

Thanks in advance...

Share this post


Link to post
Share on other sites

Running the script from SciTE, the output conole gives this:

--> Word.au3 Warning from function _WordAttach, $_WordStatus_NoMatch

--> Word.au3 Error from function _WordDocGetCollection, $_WordStatus_InvalidDataType

C:\Temp\temp-35.au3 (28) : ==> Variable must be of type "Object".:

For $oDoc in $oDoc

For $oDoc in $oDoc^ ERROR

Note the warnings/errors from word.au3.

There's something wrong with your code in those lines...

Share this post


Link to post
Share on other sites

Play with this...

#Include<file.au3>
#include<string.au3>
#include<word.au3>
#include <WindowsConstants.au3>

AutoItSetOption( "trayiconhide",1 )
AutoItSetOption( "wintitlematchmode",2 )
AutoItSetOption( "sendkeydelay",1 )
AutoItSetOption( "WinTextMatchMode",1 )

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
;If $result = 0 Then
;$docname = _StringInsert( ".docx",$docname,-5 )
;Else
;$docname = _StringInsert( ".doc",$docname,-4 )
;EndIf
MsgBox(0,"",$docname)

$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

Play with this...

#Include<file.au3>
#include<string.au3>
#include<word.au3>
#include <WindowsConstants.au3>

AutoItSetOption( "trayiconhide",1 )
AutoItSetOption( "wintitlematchmode",2 )
AutoItSetOption( "sendkeydelay",1 )
AutoItSetOption( "WinTextMatchMode",1 )

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
;If $result = 0 Then
;$docname = _StringInsert( ".docx",$docname,-5 )
;Else
;$docname = _StringInsert( ".doc",$docname,-4 )
;EndIf
MsgBox(0,"",$docname)

$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,"")

Got the error again.... :P

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

When exactly does this error appear..?? --> Variable must be of type "Object".

Edited by AvidLearner

Share this post


Link to post
Share on other sites

Once I commented out your code that appended a suffix (file entension) to the document title, it found "Document1" and ran through the end of the script without error for me.

Share this post


Link to post
Share on other sites

Once I commented out your code that appended a suffix (file entension) to the document title, it found "Document1" and ran through the end of the script without error for me.

Yeah I tried it,,,, but getting the error & terminating the program....

I dunno what to do...

Share this post


Link to post
Share on other sites

Try to run the code given below,,, it definitely will show an error saying " variable must be of type "object" "...

CODE
#Include<file.au3>

#include<string.au3>

#include<word.au3>

#include <WindowsConstants.au3>

AutoItSetOption( "trayiconhide",1 )

AutoItSetOption( "wintitlematchmode",2 )

AutoItSetOption( "sendkeydelay",1 )

AutoItSetOption( "WinTextMatchMode",1 )

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

$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

If I open up an instance of Word, that example runs fine for me.

You do have Office installed, rather than just wordpad?

Share this post


Link to post
Share on other sites

If I open up an instance of Word, that example runs fine for me.

You do have Office installed, rather than just wordpad?

Yeah I use office 2007

Share this post


Link to post
Share on other sites

Please study the messages you are getting in the SciTe console carefully. If you want help here, show the full messages you are getting (as ResNullius did).

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

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