outlook vba swap recipients -


people forward mails me , ask me reply original sender, in cc. think it's more neat put person in field , forwarder in cc. swap them. came piece of vba:

sub swap() dim objmail outlook.mailitem set objmail = application.activeinspector.currentitem  objmail    a$ = .to    .to = .cc    .cc = a$ end  set objmail = nothing end sub 

unfortunately, recipients copied text. outlook search them again in our company's address book. , large company, finds wrong person, or claims person unknown.

i've experimented objmail.recipients got weird errors. note: there might multiple people in both , cc field.

you can fetch email address out of objmail.recipients(x).address. following code works fine on machine:

public sub swap() dim objoutlook outlook.application ' use this, because i'm working in ms access dim objmail outlook.mailitem dim objrecipient outlook.recipient dim strto string dim strcc string  set objoutlook = getobject(, "outlook.application") ' use this, because i'm working in ms access set objmail = objoutlook.activeinspector.currentitem  each objrecipient in objmail.recipients ' here loop through recipients      if objrecipient.type = olto ' check if current recipient in section         strcc = strcc & ";" & objrecipient.address ' add cc string      elseif objrecipient.type = olcc ' check if current recipient in cc section         strto = strto & ";" & objrecipient.address 'add to string      end if next objrecipient  if strto <> ""     objmail.to = mid(strto, 2) ' cut off leading semicolon of our string end if  if strcc <> ""     objmail.cc = mid(strcc, 2) ' same here end if  set objmail = nothing end sub 

Comments