MS could always refocus themselves as a global company (in the legal rather than marketing-only sense), and move their HQ out of the US, then there could be no Trump tantrums affecting other countries, the worse that could happen would be some sanctions on what would then be their in-country US affiliate, with no ability to affect their other global operations whatsoever. Why haven't they followed this approach? Haven't lost enough customers yet?
MS lives by corporate contracts and there are a lot of very powerful US companies that will roll over if Trump barks - if MS had already fled the US in a legal sense they'd definitely be in a better place but trying to leave during this administration would cause Trump's ire to focus on them and likely cost them an immense amount of money. I don't particularly like MS and both office and windows are declining in quality quickly so I wouldn't be opposed to the move but... nothing would sink that ship faster than losing a bunch of large US contracts as Trump toadies demonstrate their loyalty by bravely switching to alternatives.