excel vba - VBA: Handling multiple message items -
i tried figuring out how handle multiple message objects programmatically following snippet, having trouble it. ultimately, want send message list of recipients in spreadsheet file. objects , methods job in easiest way?
dim w outlook.application dim winbox outlook.mapifolder dim objoutlookmsg outlook.mailitem dim objoutlookrecip outlook.recipient dim count, x, msgnum integer ' handle microsoft outlook set w = getobject(, "outlook.application") if err = err_app_notrunning ' open new instance if none running set w = new outlook.application winbox = w.getnamespace("mapi").getdefaultfolder(olfolderinbox) end if 'count number of emails required count = cells(1, 2).end(xldown).row msgnum = winbox.items.count x = 1 count set objoutlookmsg = w.createitem(olmailitem) msgnum = winbox.items.count next x
-------edit--------- if handle code this?
dim w outlook.application dim winbox outlook.mapifolder dim objoutlookmsg outlook.mailitem dim objoutlookrecip outlook.recipient dim count, x, msgnum integer ' handle microsoft outlook set w = getobject(, "outlook.application") if err = err_app_notrunning ' open new instance if none running set w = new outlook.application end if winbox = w.getnamespace("mapi").getdefaultfolder(olfolderinbox) 'count number of emails required count = cells(1, 2).end(xldown).row msgnum = winbox.items.count x = 1 count set objoutlookmsg = w.createitem(olmailitem) msgnum = winbox.items.count next x
this worked me...
sub testoutlooksend() dim w outlook.application dim winbox outlook.mapifolder dim objoutlookmsg outlook.mailitem dim rngaddr range, recip string set rngaddr = thisworkbook.sheets("sheet1").range("a2") set w = getobject(, "outlook.application") set winbox = w.getnamespace("mapi").getdefaultfolder(olfolderinbox) while rngaddr.value <> "" recip = rngaddr.value set objoutlookmsg = w.createitem(olmailitem) objoutlookmsg .to = recip .subject = "hello " & recip .body = "a message for" & recip .send end set rngaddr = rngaddr.offset(1, 0) loop end sub
Comments
Post a Comment