How to insert an image into spreadsheet from my resources RRS feed

  • Question

  • I'm trying to create an add-in for excel with VSTO in, I imported an image(Logo1) in the resources folder of the project, now I would like to insert in the spreadsheet (mysheet).
    I tried

    mysheet.Cells(10, 10) = My.Resources.ResourceManager.GetObject("Logo1")


    mysheett.OLEObjects.Add(ClassType:="Forms.Image.1", Link:=False, _
            DisplayAsIcon:=False, Left:=471.75, Top:=31.5, Width:=293.25, Height _
    .Image1.Object.Picture = My.Resources.ResourceManager.GetObject("Logo1")
    don't works

    • Edited by M.Berner Saturday, May 12, 2012 4:57 PM
    Saturday, May 12, 2012 4:57 PM

All replies

  • 1.Insert the sheet reference before the name

    If it is in activesheet then




    2.I see the Image object has no property as Object but it has one Picture Property but it is of stdPicture type.Not sure how it works.

    Sunday, May 13, 2012 8:25 AM
  • thanks,I insert other code I will be more clear

    Imports Microsoft.Office.Tools.Ribbon Imports System.Drawing Imports Microsoft.Office.Interop.Excel Imports Microsoft.Office.Tools.Excel Imports ProjectImage.My.Resources Public Class RibbonImage Private Const WORKSHEET_IMAGE = "Image" Private Sub ButtonImageFirst_Click(ByVal sender As System.Object, ByVal e As Microsoft.Office.Tools.Ribbon.RibbonControlEventArgs) Handles ButtonImageFirst.Click On Error Resume Next 'Discard any errors and continue execution Dim blnSheetFound As Boolean = False Automatically it is set to be False (worksheet not found level) Dim wsSheetImage As Excel.Worksheet = CType(Globals.ThisAddIn.Application.Worksheets(WORKSHEET_IMAGE), Excel.Worksheet) If Err.Number = 0 Then 'If NO errors are occured, that means the "Data" worksheet does exists... If MsgBox("The worksheet " & Chr(34) & WORKSHEET_IMAGE & Chr(34) & " already exists in the current workbook. Do you like to clear all data in it and set the new ones?", MsgBoxStyle.YesNo + MsgBoxStyle.Question) = MsgBoxResult.Yes Then wsSheetImage.Rows.Clear() blnSheetFound = True Else GoTo ExitSub2 End If End If Err.Clear() 'Clear if any errors have been recorded in above code execution If blnSheetFound = False Then Globals.ThisAddIn.Application.Worksheets.Add() wsSheetData = CType(Globals.ThisAddIn.Application.ActiveSheet, Excel.Worksheet) wsSheetData.Name = WORKSHEET_IMAGE End If With wsSheetImage Globals.ThisAddIn.Application.StatusBar = "Getting started..." 'This will be shown in the MS-Excel's status bar .Cells.Font.Name = "Courier New"

    Here I put the image on the sheet
    • Edited by M.Berner Sunday, May 13, 2012 9:30 AM
    Sunday, May 13, 2012 9:30 AM
  • I understand you want to insert one image.I hope following snippet can help you in guiding towards your goal.The below will insert a pic in activecell and size with the cell.If you want to specify the postion..suppose A1 then just replace .TopLeftCell with Range("A1").

    Sub InsertShape()

        Dim Pic As Picture
        Set Pic = ActiveSheet.Pictures.Insert("g:\1.jpg")
        With Pic
            .ShapeRange.LockAspectRatio = 0
            .Height = .TopLeftCell.Height
            .Width = .TopLeftCell.Width
            .Left = .TopLeftCell.Left
            .Top = .TopLeftCell.Top
        End With

    End Sub

    Sunday, May 13, 2012 10:48 AM
  • Thanks but  my problem is that the add-in must be shared. The path must be from internal resources no outside because my image is not present in your pc.
    • Edited by M.Berner Sunday, May 13, 2012 11:21 AM
    Sunday, May 13, 2012 11:20 AM
  • If one image is not in PC then how will you retrieve it.

    Not sure if using Win APIs.

    Sunday, May 13, 2012 3:21 PM
  • The image is into the installation package like example the images of the ribbons
    Sunday, May 13, 2012 4:10 PM
  • I found this but I not understand

    • Edited by M.Berner Tuesday, May 15, 2012 9:03 AM
    Tuesday, May 15, 2012 9:02 AM