Search for email subject in outlook from excel using vba? -


i trying search email specific subject in outlook excel using following macro:

sub work_with_outlook()   set olapp = createobject("outlook.application")       dim olns outlook.namespace      dim fldr outlook.mapifolder      dim olmail variant      dim sir() string       set olapp = new outlook.application      set olns = olapp.getnamespace("mapi")      set fldr = olns.getdefaultfolder(olfolderinbox)      set mytasks = fldr.items    set olmail = mytasks.find("[subject] = ""*desired subject*""")    if not (olmail nothing)    sir = split(olmail.body, vbcrlf)    = 1 ubound(sir)    activeworkbook.sheets("sheet1").cells(i, 1).value = sir(i)    next    olmail.delete    end if  end sub 

my problem error in excel saying user defined type not defined on line:

dim olns outlook.namespace

please can show me going wrong? thanks,

you need add reference outlook in vba project.

in vba editor menu bar click tools -> references , check microsoft outlook 14.0 object library (version number can different 14.0, depending on version of ms office).


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -