The sentence has some problems. While any native speaker would understand that "he" and "him" referred to the same person, grammatically, it doesn't work that way. The "but having bumped ..." part should modify the same person who is "he" in the first part of the sentence.
At the beginning of the week, Joe looked cheerful, but having bumped into Roger on Wednesday [and learning that Roger had gotten the promotion he wanted], Joe looked depressed.
I expect you mean for it mean "At the beginning of the week, he looked cheerful, but when I bumped into him on Wednesday, he looked depressed." Here the "he" and "him" (and last "he") all refer to the same unnamed male.
I suggest you use quotation marks to set off the sentence you want to ask about.
Interested in Language