A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data
Nifty piece of code. Though perhaps one day Excel will be updated so adding a picture as a cell background will be a simple function.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I want to add a picture as cell background and still see the text in the cell.
I want the picture to be constrained to the cell size, so that when the cell is copied, the picture does not try to resize in the new location.
I have tried doing this, but the only thing I can seem to do is place the image over the cell and then may it transparent, which results in a very poor effect. It also resizes when copied to a new location.
I have also tried to inert it as a background, but this seems to be for the entire page and not just the cell.
Does anyone know how to do this?
A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data
Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.
Nifty piece of code. Though perhaps one day Excel will be updated so adding a picture as a cell background will be a simple function.
Hi,
NEW
scenario
Add picture in cell C3 (picture width = cell width / Ratio = True) as background (note: embedded in a shape)
before
.
after
.
======================
vba macro
Option Explicit
Dim ws As Worksheet
Dim r As Range
Dim shp As Shape
Dim sURL As String
'
Sub Add_Pic_in_Cell_C3()
'## 06/03/2024 ##
sURL = "https://img.freepik.com/free-photo/river-flowing-through-trees-mountains-scotland_181624-24054.jpg"
Set ws = ActiveSheet
Set r = ws.Range("C3")
If ws.Shapes.Count > 0 Then
For Each shp In ws.Shapes
If Not Intersect(shp.TopLeftCell, r) Is Nothing Then
shp.Delete
End If
Next shp
End If
Set shp = ws.Shapes.AddPicture(sURL, False, True, 0, 0, -1, -1)
With shp
.LockAspectRatio = msoTrue
.Left = r.Left
.Top = r.Top
.Width = r.Width
.TopLeftCell.RowHeight = .Height
End With
shp.Delete
Set shp = ws.Shapes.AddTextbox(msoTextOrientationHorizontal, r.Left, r.Top, r.Width, r.Height)
shp.Line.Visible = msoFalse
With shp.Fill
.Visible = msoTrue
.UserPicture sURL
.TextureTile = msoFalse
.RotateWithObject = msoTrue
.Transparency = 0.6
End With
End Sub
=====================
NOTE:
sample:
"C:\Users\otaso\Pictures\Tangram\cat.jpg"
Thank you for the response and the code.
I used the code and it ran as expected, now there is a picture and text both in the same cell. As you can see from the image below, the cell contains the text and the picture.
This is as close as I have come so far.
However, the text is covered by the picture.
Is there a way to place the text in front of the picture?
This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.
Comments have been turned off. Learn more
This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.
Comments have been turned off. Learn more