It's more than just "trying to get ahead of google".
They will also likely "poison the water supply" of google's main business by blitzing the advertising market with lower prices, forcing google to loose income.
They also gain the HUGE online services of Yahoo mail and IM, making it a powerhouse in the IM business, which is a lot more advertising dollars as well. Google's IM network is limited, and AOL is...well, AOL.
They also aquire flickr, HotJobs, GeoCities, and many other stuff. Many of these products can be folder up quickly and easily into "Microsoft Live"....likely within 2 years.
There's also a ton of technologies and talents owned by Yahoo! that Microsoft can make good use of. Yes....some of those talents probably hate Microsoft and will quit, but eh almighty dollar will keep a good amount of them.