Yes, it should be possible. To get a start on it, I suggest you turn on the
macro recorder, carry out the steps manually, stop the recorder, look at the
code and modify it as needed. If you get stuck, post back with sufficient
details (post the code, what you expected to happen, what did happen) so
somebody can help.