Steve Ballmer, CEO of Microsoft Corp., said for the first time in public he was relieved his company didn't buy Yahoo in 2008.

Ballmer laughed when he was asked if he was glad he didn't buy the search engine competitor.

"You know, times change. Any CEO who might have want something before the market crashed in 2008. You say: 'Were you glad you didn't buy something?' Hallelujah," Ballmer said at the Web 2.0 Summit in San Francisco on Tuesday.

"Sometimes you're lucky," Ballmer added.

In 2008, Microsoft launched a bid of $47.5 billion for Yahoo. But Yahoo, at the time led by CEO Jerry Yang, dropped the offer angering its shareholders and eventually, prompting Yang's resignation.

Watch Steve Ballmer's comments below: