Micro Focus QTP (UFT) Forums
The operation failed. An object could not be found. - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: The operation failed. An object could not be found. (/Thread-The-operation-failed-An-object-could-not-be-found)



The operation failed. An object could not be found. - kotaramamohana - 10-11-2010

Hi Friends,

I have an issue in the email checking, and i have given the error below. And has also attached the code i used. If i am not declaring the variables its working perfectly, if i use this in the framework it throws error. Please help me to resolve this issue.

---------
Error:
---------
The operation failed. An object could not be found.

Line (63):
Code:
"set objsubfolder = objparentfolder.folders(objfolder.name)".

----------------------------------------

Code:
Option Explicit
Dim olapp,inbox,fold,colfolders,objfolder,objsubfolder,objparentfolder,mail,col,strMailSub1,strMailSub2,strMailBody1,strMailBody2,strMailBody3


Call fnResetPassword()

Public Function fnResetPassword()
    
        
    set olapp = createobject("outlook.application")
    set inbox = olapp.getnamespace("mapi").folders
    
    for each fold in inbox
    'msgbox fold.name
    'If fold="Razoo Mails" Then
        getsubfolders(fold)
    'End If
    next
    
    'msgbox inbox.count

End Function    
        
    sub getunreadmails(objfolder)
    
    set col = objfolder.items
    for each mail in col
    If mail.unread then
         strMailSub1=mail.subject
      strMailSub2=split(strMailSub1,"-")
        If Trim(strMailSub2(1))="Password reset request" Then
        
        'datatable.SetCurrentRow i
    'msgbox mail.subject
    
    'datatable.Value("Subject","Global")=mail.subject
    'msgbox mail.sendername
    'msgbox mail.body
    
    strMailBody1=mail.body
    strMailBody2=split(strMailBody1,"http://")
    strMailBody3=split(Trim(strMailBody2(1)),"edit")
    'Datatable.Value("Expected","SubDriver[SubDriver]")=Trim(strMailBody3(0))&"edit"
    strResetUrl=Trim(strMailBody3(0))&"edit"
    'Msgbox "http//" &z(0) &"/edit"
    msgbox strResetUrl
    
    'msgbox mail.senton
    mail.unread=false
    End if
    end if
    next
    end sub


    
    sub getsubfolders(objparentfolder)
            set colfolders = objparentfolder.folders
            'msgbox colfolders.count
            For each objfolder in colfolders
                    'msgbox objfolder.name
                set objsubfolder = objparentfolder.folders(objfolder.name)
                   msgbox objsubfolder.name
                if objfolder.name<>"notes" then
                    getunreadmails(objfolder)
                end if
                getsubfolders objsubfolder
            next
    end sub




Regards,
Ram


RE: The operation failed. An object could not be found. - anil2u - 08-07-2013

Hi,

Can you try setting the initialized objects to 'Nothing' at the end of the sub routines, when they are of no use. I had same error once and it worked for me. I think without the explicit declaration the variables are created and destroyed within the scope of the function, so you are not getting the error when you are not using 'Option explicit'

Let me know if it helps.

Cheers