如何在Excel中用相應的圖片替換文本?
如何在Excel中用相應的圖片替換文本?
假設,我在工作表中有一個產品名稱列表,并且在計算機磁盤中有一個文件夾,其中包含產品名稱的對應圖片。 現在,我需要在Excel中查找產品名稱并將其替換為它們的相對圖像,而不必一一插入,如下圖所示。 在Excel中是否有任何好的快速解決方案來處理此工作?
用VBA代碼用相應的圖片替換文本
用相應的圖片替換文字 Kutools for Excel
通常,沒有簡單直接的方法可讓我們在Excel中基于文本字符串插入相對圖片,但是,以下VBA代碼可以幫助您將文本替換為其對應的圖片。
1. 媒體 Alt + F11鍵 顯示 Microsoft Visual Basic應用程序 窗口。
2。 在窗口中,單擊 插頁 > 模塊 以顯示一個新的模塊窗口,然后將以下VBA代碼復制并粘貼到 模塊 窗口。
VBA代碼:用相應的圖片替換文本
Sub InsertPicture()
Upadateby Extendoffice
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...
Copy
版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。
版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。