Home Ask Login Register

Developers Planet

Your answer is one click away!

Duraholiday February 2016

Image from Excel to vb.net Picturebox

I have found many questions for the opposite vb.net to excel but none for getting a picture from an excel cell(row,column) into a picture box. My app is a template that gets strings of text from an excel file. Which works fine but now I am trying to also transfer pictures. I have tried picSpindle.Image = shXL.Cells(19, 2).Value but doesn't do anything. Does not error out though!

Will copy and paste work?


Imports System
Imports System.IO
Imports System.Text
Imports Excel = Microsoft.Office.Interop.Excel
Public Class Form1
    Dim appXL As Excel.Application
    Dim wbXl As Excel.Workbook
    Dim shXL As Excel.Worksheet
    Dim raXL As Excel.Range
    Dim PartID As String
    Dim RefCard As String

    Private Sub Form1_Activated(sender As System.Object, e As System.EventArgs) Handles MyBase.Activated
        'Dispaly Brembo Logo
        picLogo.SizeMode = PictureBoxSizeMode.StretchImage

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        'Read File Source with part number ******************Example From TXT
        PartID = ("19.N111.10")

        ' Start Excel and get Application object.
        appXL = CreateObject("Excel.Application")
        appXL.Visible = False

        'Open Reference Card*************************************************************************************

        wbXl = appXL.Workbooks.Open("C:\Users\aholiday\Desktop\Visual Studios Projects\Reference Card App\" & PartID & ".xlsx")
        shXL = wbXl.Worksheets("Sheet1")

        ' Copys Reference Card Text from Cells To App labels
        lblCODE.Text = shXL.Cells(3, 9).Value
        lblREV.Text = shXL.Cells(3, 13).Value
        lblDate.Text = shXL.Cells(5, 9).Value
        lblCustomer.Text = shXL.Cells(8, 2).Value
        lblPart.Text = shXL.Cells(11, 2).Value
        lblSpindleType.Text = shXL.Cells(15, 2).Value


Claudius February 2016

shXL.Cells(19, 2).Value

and so on won't work because pictures aren't store in cells but over them meaning values of these cells will be nothing

try these links




Baro February 2016

The images are not inside a cell. But the coordinates of the top left corner point to a cell, with this code above you can make your own function that searches through images.

You can do so:

    shXL = wbXl.Worksheets("Sheet1")

    ' # Loop for all Shapes 
    ' But I don't know what other controls over 
    '    the images are considered "shapes",
    '    Perhaps the best way is to verify that 
    '    in the "clipboard" there is truly a picture
    For i = 0 To shXL.Shapes.Count - 1


        ' # get the pictures and copy to clipboard

        ' # paste the picture in the pictureBox from clipboard
        'PictureBox1.Image = Clipboard.GetImage


        MsgBox(shXL.Shapes.Item(i).Name) ' the name in excel
        MsgBox(shXL.Shapes.Item(i).AlternativeText) 'the name of the file
        MsgBox(shXL.Shapes.Item(i).TopLeftCell.Column) 'the column position (of the top left corner)
        MsgBox(shXL.Shapes.Item(i).TopLeftCell.Row) 'the row position (of the top left corner)
        MsgBox(shXL.Shapes.Item(i).Width) 'the with in px
        MsgBox(shXL.Shapes.Item(i).Height) 'the height in px
        MsgBox(shXL.Shapes.Item(i).Top) 'the top in px
        MsgBox(shXL.Shapes.Item(i).Left) 'the left in px

Post Status

Asked in February 2016
Viewed 1,119 times
Voted 5
Answered 2 times


Leave an answer

Quote of the day: live life