By Sarah Nassauer

Doug McMillon has worked to remake Walmart Inc. since becoming its chief executive six years ago. He has all but stopped building new U.S. stores, spent roughly $20 billion on e-commerce startups and retreated from Brazil and other countries.

The 53-year-old's latest gambit would be the farthest departure from the company's traditional roots, trying to turn one of the world's biggest social-media apps into a Walmart storefront.

Walmart said Thursday it was making a joint bid with Microsoft Corp. for TikTok's U.S. operations, the popular video-sharing app that is facing a potential ban in the U.S. from the Trump administration over national-security concerns. TikTok is owned by Beijing-based ByteDance Ltd.

The retail giant wants to use TikTok to sell products to U.S. consumers spending hours swiping through goofy videos of dance routines, lip-syncing and pranks. But Walmart also wants to be a bigger player in digital advertising. It could use TikTok's audience to sell ad space to other companies, mainly its own suppliers, according to people familiar with the operation.

Last year, the company announced plans to create a digital-advertising network that would compete for marketing dollars with Amazon.com Inc., Google and others. Walmart brought its digital-ad sales unit in house and hired ad executives to sell space on walmart.com.

The retail giant hopes that the marketing chief of a large branded manufacturer can "now think about Walmart as a network I can go advertise on," Steve Bratspies, then-chief merchandising officer for Walmart U.S., said last year. Mr. Bratspies is currently the CEO of Hanesbrands Inc.

Those efforts are born out of a fear of Amazon's financial model, which earns the bulk of profits from computing services and selling advertising. It uses those profits to partially fund costly superfast shipping on a nearly endless array of products sold online, eating into Walmart's share of retail sales.

Mr. McMillon bought e-commerce startup Jet.com in 2016 for $3.3 billion to advance its own online shopping service and put founder Marc Lore at the head of Walmart's U.S. e-commerce business. Then, Mr. McMillon paid $16 billion in 2018 for control of Flipkart Group, an Indian e-commerce startup that Amazon also pursued. He has explored other ways to tap its stores for revenue, such as rolling out health-care clinics and exploring a potential cloud-computing service.

With a stake in TikTok, Walmart could grow its e-commerce business, expanding product sales through the social-media app or promoting walmart.com.

A purchase would put Walmart and Microsoft in direct competition with Facebook Inc. and other social-media companies working to boost revenue by letting users shop inside social-media posts.

Facebook's Instagram is working to grow shopping through the image-based app. Brands or people selling items can link to their shopping websites through Instagram, and the social-media network also lets shoppers who share a payment method buy products directly in the app. The seller ships the products to the buyer, not Instagram.

"The lines are blurring between traditional shopping, digital shopping and social media," said Michael Lasser, retail analyst at UBS Group AG. "Walmart needs more exposure to this trend."

Walmart's stock rose 4.5% to $137 by market close Thursday on news of the TikTok bid. There are still many hurdles to overcome before any deal gets done and other suitors are circling TikTok.

For Mr. McMillon, a bid for TikTok would align with many of his personal interests and wider goals for the company, including improving Walmart's perception among more shoppers, adding more cool-factor and appeal for wealthier consumers. Walmart's core customers are households earning around $45,000 a year, low-income shoppers strapped for cash.

Mr. McMillon has long been interested in the power of entertainment to win hearts and change minds about Walmart's brand, as well as drive excitement about new products, according to people familiar with his thinking. He likes to emphasize new movie releases in stores to drive related product sales, say some of these people.

In 1994, Mr. McMillon, then a middle-manager, wrote a letter to an executive outlining his vision for the company, including the growing role of technology and the increasing popularity of "video retailing," which at the time meant TV shopping networks.

TikTok's user base skews young, even by social-media standards, and that is surely an appeal for Walmart as it is for the app's other suitors. But as a retailer rather than a tech company, Walmart could face challenges in maintaining the app's knack for innovation and edgy appeal to young people. And many teen TikTok users have no credit cards.

A stake in TikTok would thrust Walmart into uncomfortable territory, part-watchdog for a host of complex topics such as sexual content on the platform, bullying through videos, and political content online.

Not all of Walmart's digital pursuits have worked out. In 2010, Walmart bought the Vudu movie-rental and streaming service but it was eclipsed by Netflix Inc. and others. In April 2020, Walmart sold Vudu to Comcast Corp. It has wound down all of Jet.com's operations and sold off several niche e-commerce startups that it acquired, including ModCloth and just this week Shoes.com.

Mr. McMillon, an Arkansas native and son of a dentist and a homemaker, joined Walmart nearly 30 years ago loading trucks as a summer job. He rose through the ranks and became CEO in 2014. He is a technology buff with 44,000 followers on Instagram, who also talks regularly about his Christian beliefs, weaving "God is good," into speeches.

Under Mr. McMillon, the company has been more outspoken than ever before on social issues, taking a stance supporting gay rights and limiting gun sales in the wake of a mass shooting at an El Paso, Texas, Walmart store last year. More recently, Walmart has highlighted racial justice after several incidents of police violence against Black people and related protests.

Mr. McMillon has also become a leading face of American corporations, taking over earlier this year as chairman of the Business Roundtable, an advocacy group for business executives. He has also developed close ties to the White House. President Trump has praised Walmart and other big chains for helping with Covid-19 testing efforts during the pandemic.

"Although the world of social media seems a million miles away from selling cans of soup, Walmart's interest in buying TikTok underlines the seriousness of its digital ambitions," said Neil Saunders, managing director of GlobalData Retail.

Write to Sarah Nassauer at sarah.nassauer@wsj.com