Solved

VB.net Excel Add-in Add a picture to a cell from resources

Posted on 2014-03-10
3
727 Views
Last Modified: 2014-03-11
Hi

How do I call the following code to insert an image from Resouces. oPicPath is the file path. What would I set this to? I am also getting the error "msoTrue is not declared"


    Sub Add_Pic_To_Cell(ByVal oRow As Long, ByVal oColumn As Integer, ByVal oPicPath As String)
        With Globals.ThisAddIn.Application.ActiveSheet.Pictures.Insert(oPicPath)
            With .ShapeRange
                .LockAspectRatio = msoTrue
                .Width = 75
                .Height = 100
            End With
            .Left = Globals.ThisAddIn.Application.ActiveSheet.Cells(oRow, oRow).Left
            .Top = Globals.ThisAddIn.Application.ActiveSheet.Cells(oRow, oRow).Top
            .Placement = 1
            .PrintObject = True
        End With
    End Sub
0
Comment
Question by:murbro
  • 2
3 Comments
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 500 total points
ID: 39916980
I tried this simple macro and working fine for me

Sub Macro1()
'
' Macro1 Macro
'
Dim oRow As Long
Dim oColumn As Integer
Dim oPicPath As String
oRow = 1
oColumn = 1
oPicPath = "C:\PA_ERROR.jpg"


 With ActiveSheet.Pictures.Insert(oPicPath)
            With .ShapeRange
                .LockAspectRatio = msoTrue
                .Width = 75
                .Height = 100
            End With
            .Left = ActiveSheet.Cells(oRow, oRow).Left
            .Top = ActiveSheet.Cells(oRow, oRow).Top
            .Placement = 1
            .PrintObject = True
        End With
'
End Sub

Open in new window

0
 

Author Comment

by:murbro
ID: 39917035
Hi. Thanks but I am looking specifically to add a pic from my project resources
0
 

Author Closing Comment

by:murbro
ID: 39919854
thanks
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question