Hi,
Please try the following code to see if it meets your need.
Using the CopyPicture method to copy the picture.
Using the Paste method of xlWorksheet to paste the picture on the cell.
After pasting, using xlWorksheet.Shapes(xlWorksheet.Shapes.Count) to access the last shape in the Shapes collection.
xlWorksheet.Range("B1").Select()
Dim left As Double = xlWorksheet.Range("B1").Left
Dim top As Double = xlWorksheet.Range("B1").Top
Dim width As Double = xlWorksheet.Range("B1").Width
Dim height As Double = xlWorksheet.Range("B1").Height
xlWorksheet.Range("B1").CopyPicture(Excel.XlPictureAppearance.xlScreen, Excel.XlCopyPictureFormat.xlBitmap)
xlWorksheet.Paste(xlWorksheet.Range("B1"))
Dim xlShape As Excel.Shape = xlWorksheet.Shapes(xlWorksheet.Shapes.Count)
xlShape.LockAspectRatio = Microsoft.Office.Core.MsoTriState.msoFalse
xlShape.Left = left
xlShape.Top = top
xlShape.Width = width
xlShape.Height = height
Dim desktopPath As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
Dim savePath As String = IO.Path.Combine(desktopPath, "ImageOverCell.xlsx")
xlWorkbook.SaveAs(savePath)
Best Regards.
Jiachen Li
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.