Switch from picture in a cell to picture over cell


Hi All, I want a code in VB.net to switch from picture in a cell to picture over a cell. The below is the code I have so far. Next step will be to select the cell B1 and make the picture over cell and save it in the desktop that picture. Thanks for your help

xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
xlApp.DisplayAlerts = True  
xlWorkbook = xlApp.Workbooks.Add()
xlWorksheet = xlWorkbook.Worksheets(1)
xlWorksheet.Range("A1").Value = "https://a360.co/3UKfwfrwkZj"
xlWorksheet.Range("B1").Value = "=IMAGE(""https://api.qrserver.com/v1/create-qr-code/?size=80x80&data=""&A1)"

An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,657 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Jiachen Li-MSFT 28,781 Reputation points Microsoft Vendor


    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.

            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)
            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")

    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.

    0 comments No comments