One of my Yorkies peed when we came home, when company came over and talked to her. It was so upsetting. I talked to my vet about it and he said it was called Involuntary Urination. He said to follow these steps and it worked.
1. When you first walk in the door, don't look at them, don't talk to them. Ignore them for a little bit and let them get settled down some. Then take them outside and give them attention.
2. Tell guests to do the same.
We did this for a few weeks and it solved the problem. We have not had to worry about it for years.