VBA Excel get values of updated cells -
ok, have been struggling problem time. new vba bear me.
what need program grab cell values in workbook updated , push data email. let's range want watch a4:a100. user puts in sales order number a10 , a11. need program take values cells , insert them email when workbook saved. have code @ end of question emails list of people when workbook saved. have email contain id's (column a) of records entered. thank help.
private sub workbook_beforesave(byval saveasui boolean, _ cancel boolean) dim answer string answer = msgbox("would save , email notification?", vbyesno, "save , email") if answer = vbno cancel = true if answer = vbyes 'open outlook type stuff set outlookapp = createobject("outlook.application") set olobjects = outlookapp.getnamespace("mapi") set newmsg = outlookapp.createitem(olmailitem) 'add recipients newmsg.recipients.add ("will.smead@cablevey.com") newmsg.recipients.add ("will.smead@cablevey.com") 'add subject newmsg.subject = "update on credit hold list" 'add body newmsg.body = "please check credit hold excel file on s drive updates." newmsg.display 'display newmsg.send 'send message 'give conformation of sent message msgbox "file saved , messages sent.", , "saved , sent" end if 'save document 'me.worksheets.save end sub
you'll need worksheet change event in sheet you're watching -
sub worksheet_change(byval target range) if not intersect(target, range("a4:a100")) nothing dim ws worksheet set ws = sheets("changes") dim lastrow integer lastrow = ws.cells(rows.count, "a").end(xlup).row ws.cells(lastrow + 1, 1) = target.address ws.cells(lastrow + 1, 2) = target end if end sub
you'll need create sheet named changes
, put in row 1 col & b "address" , "new value" -
you can see had misspelling , had correct it. should sort stuff out in macro above.
Comments
Post a Comment