My B does that too. We have gates up and some times we step over them rather than swing them open to leave. We've gotten nipped on the butt! I've started getting him used to sitting and staying as I leave the room, and treating and praising him when he stays calm. It's been working petty well. Good luck!
My husband and I knew that our next door neighbor was going through a divorce around Christmas time. Over the past years we've occasionally helped each other with letting each others dogs out. So, we knew she liked dogs, but we weren't particularly close. We wanted to spread a little kindness, so we all (B included) brought cookies to her. She wanted us all to come and have a cookie with her. I realized that Darwin was being awfully quiet and looked over at him in time to see him lift his leg and proceed to pee all under her tree all over her Christmas presents!!!