How to insert picture into text box?
By default, we can insert a picture or image into a worksheet as quickly by using the Insert function, but, this feature is not applied to inserting a picture into a textbox. With this article, I can help you to insert a picture into a textbox as you need.
Insert a picture or image into a textbox with VBA code
Insert a picture or image into a textbox with VBA code
To insert a picture into a textbox, the following VBA code may help you, please do as this:
1. Insert a textbox by clicking Insert > Text Box, and then draw a textbox, see screenshot:
2. Then hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.
3. Click Insert > Module, and paste the following code in the Module Window.
VBA code: Insert a picture into text box:
Sub ShapePicture()
Dim xSh As Shape
Dim xPic As IPictureDisp
Dim xFileName As String
xFileName = "C:\Users\DT168\Desktop\pictures\Apple.JPG"
Set xPic = LoadPicture(xFileName)
Set xSh = Sheets("Sheet4").Shapes(1)
xSh.Height = xPic.Height / xPic.Width * xSh.Width
Set xPic = LoadPicture("")
Set xPic = Nothing
xSh.Fill.UserPicture xFileName
End Sub
Note: In the above code, Sheet4 is the sheet name which contains the text box you want to insert picture, and C:\Users\DT168\Desktop\pictures\Apple.JPG is the picture path of the picture you want to insert, you should change them to your need.
4. And then press F5 key to run this code, the specific image will be inserted into the text box at once, and you can edit the textbox as you need, see screenshot:
Related articles:
How to set a default value in a textbox?
How to allow only numbers to be input in text box?
How to apply spell check in textbox?
How to change textbox color based on value in Excel?
Best Office Productivity Tools
Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time. Click Here to Get The Feature You Need The Most...
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!






