如何在Excel中用相应的图片替换文本?
假设,我在工作表中有一个产品名称列表,并且在计算机磁盘中有一个文件夹,其中包含产品名称的对应图片。 现在,我需要在Excel中查找产品名称并将其替换为它们的相对图像,而不必一一插入,如下图所示。 在Excel中是否有任何好的快速解决方案来处理此工作?
用VBA代码用相应的图片替换文本
用相应的图片替换文字 Kutools for Excel
用VBA代码用相应的图片替换文本
通常,没有简单直接的方法可让我们在Excel中基于文本字符串插入相对图片,但是,以下VBA代码可以帮助您将文本替换为其对应的图片。
1. 媒体 Alt + F11键 显示 Microsoft Visual Basic应用程序 窗口。
2。 在窗口中,单击 插页 > 模块 以显示一个新的模块窗口,然后将以下VBA代码复制并粘贴到 模块 窗口。
VBA代码:用相应的图片替换文本
Sub InsertPicture()
Upadateby Extend
office
Dim xPath As String
Dim xLastRow As Long
Dim Rng As Range
Dim WorkRng As Range
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
Application.ScreenUpdating = False
xPath = "C:\Users\dt\Desktop\Fruits\"
If Right(xPath, 1) <> "\" Then xPath = xPath & "\"
xLastRow = Cells(Rows.Count, "A").End(xlUp).Row
For Each Rng In WorkRng
If Rng.Value <> "" Then
If Dir(xPath & Rng.Value & ".jpg") <> "" Then
ActiveSheet.Pictures.Insert(xPath & Rng.Value & ".jpg").Select
With Selection.ShapeRange
.LockAspectRatio = msoFalse
.Left = Rng.Left
.Top = Rng.Top
.Width = Rng.Width
.Height = Rng.Height
End With
Rng.ClearContents
Else
Rng.Value = "N/A"
End If
End If
Next
Application.ScreenUpdating = True
End Sub
3. Then press F5 key to run this code, and select the data range that you want to insert the corresponding pictures in the popped out dialog, see screenshot:
4. And then click OK button, all the corresponding images with the size as the same as the cells will be replaced with the original text, see screenshots:
Notes:
1. In the above code, you need to change the folder path of the pictures to your need, xPath = "C:\Users\dt\Desktop\Fruits\".
2. If there are no corresponding pictures to match the text, the error N/A will display.
Replace text with corresponding pictures with Kutools for Excel
As the above code difficult to master, here, I will introduce you an easy and powerful tool - Kutools for Excel, with its Match Import Pictures feature, you can quickly and conveniently to insert the pictures to match the list of text.
Kutools for Excel : with more than 300 handy Excel add-ins, free to try with no limitation in 30 days.
Go to DownloadFree Trial 30 daysPurchasePayPal / MyCommerce
After installing Kutools for Excel, please do as this:
1. Click Kutools Plus > Import & Export > Match Import Pictures, see screenshot:
2. In the Match Import Pictures dialog box, click button to select the range that you want to match with the pictures, see screenshot:
3. Then in the Match Import Pictures dialog, click Add > File or Folder to find the pictures that you want to insert, see screenshot:
4. After inserting the corresponding images, then click Import size button, in the following Import Picture Size dialog, specify one option for the size of your picture. See screenshot:
5. Then click OK > Import, and then choose one cell to locate your relative images from the popped out Match Import Pictures dialog (you can also select the original cell of the text), see screenshot:
6. And then click OK button, all the pictures which match with the text have been inserted into the worksheet, see screenshot:
Notes:
1. If there are no matched pictures with the text, the cell will not insert anything.
2. If you want to insert pictures horizontally, you can check Fill horizontally cell after cell in the Import order section.
Download and free trial Kutools for Excel Now !
Demo: Replace text with corresponding pictures with Kutools for Excel
Kutools for Excel: with more than 300 handy Excel add-ins, free to try with no limitation in 30 days. Download and free trial Now!
Best Office Productivity Tools
Transform Hours into Minutes with Kutools for Excel!
Ready to supercharge your Excel tasks? Harness the power of Kutools for Excel - your ultimate time-saving tool. Streamline intricate tasks and glide through your data like a pro. Experience Excel at lightning speed!
Why You Need Kutools for Excel
🛠️ Over 300 Powerful Features: Kutools is packed with more than 300 advanced features, simplifying your work in over 1500 scenarios.
📈 Superior Data Processing: Merge cells, remove duplicates, and perform advanced data conversions – all without breaking a sweat!
⏱️ Efficient Batch Operations: Why put in extra effort when you can work smart? Import, export, combine, and tweak data in bulk with ease.
📊 Customizable Charts and Reports: Access a broad variety of additional charts and generate insightful reports that tell a story.
🗄️ Powerful Navigation Pane: Gain an advantage with the robust Column Manager, Worksheet Manager, and Custom Favorites.
📝 Seven Types of Drop-down Lists: Make data entry a breeze with drop-down lists of various features and types.
🎓 User-Friendly: A breeze for beginners and a powerful tool for experts.
Download Now and Soar Through Time with Excel!
Read More... Free Download... Purchase...
Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier
Enable tabbed editing and reading in
Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
Open and create multiple documents in new tabs of the same window, rather than in new windows.
Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
Read More... Free Download... Purchase...