0

i'm new to vb.net, and i want to open an existing excel file, and insert an image to a specific cell, such as 'C16' for exemple.

It's been three days and i'm searching about this topic, but what i found was just creating a new excel file and insert a picture to it.

Anybody can help?

  • The way of inserting a picture into a cell for an existing file shouldn't be different from the way for a new one. Once you opened it, just add your image like you would do. Look at this link: http://www.visual-basic-tutorials.com/WriteToExcel2007.php. Once you did this, if you still can't, show us some code and we will point you what is missing. – Fjodr May 28 '15 at 13:52

3 Answers3

0

The code can be used is like this:

ActiveSheet.Pictures.Insert(pathForPicture & "\" & pictureName & ".jpg").Select 'Path to where pictures are stored

For more reading from this site: VBA to insert embeded picture excel

How to insert a picture into Excel at a specified cell position with VBA

Community
  • 1
  • 1
0

I've already found a solution: please find it below

                    workbook = APP.Workbooks.Open(filepath)
                    worksheet = workbook.Worksheets("name of the excel sheet")

                    worksheet.Visible = True
                    Dim pic1 As String = "picture path"
                    worksheet.Range("I51:I51").Select() 

I51 is the cell where i want my picture

                    worksheet.PageSetup.Zoom = False
                    worksheet.PageSetup.FitToPagesWide = 1
                    worksheet.PageSetup.FitToPagesTall = 1
                    Dim opicture1 As Object
                    opicture1 = worksheet.Pictures.Insert(pic1)
0

I would like to provide my codes.

Dim picPath As String = "C:\..."
Dim _Left   = xlWorkSheet.Range(WorkSheet.Cells(i, j).Address).Left
Dim _Top    = xlWorkSheet.Range(WorkSheet.Cells(i, j).Address).Top
Dim _Width  = xlWorkSheet.Range(WorkSheet.Cells(i, j).Address).Width
Dim _Height = xlWorkSheet.Range(WorkSheet.Cells(i, j).Address).Height
WorkSheet.Shapes.AddPicture(picPath, False, True, _Left, _Top, _Width, _Height)

picPath is the path of the image you want to insert.

(i,j) is the index of the cell where you want to insert an image.

fmnijk
  • 411
  • 5
  • 12