Inserting Images i get Error "variable not defined" when coded in Excel 2010 but runs perfectly in Excel 2013

NimishK

Well-known Member
Joined
Sep 4, 2015
Messages
684
Hello

When inserting Images i get Error "variable not defined" using the below code in Excel 2010 but runs perfectly in Excel 2013 which i am currently using

Code:
Set s = ActiveSheet.Shapes.AddPicture2(picPath, False, True, rr1.Left + 48.48, rr1.Top + 11, 60.0944882, 462.047244, msoPictureCompressTrue)

error is highlited on msoPictureCompressTrue

So any guidance will be appreciated to prevent the above error and coding to run smoothly in all versions of Excel

https://www.mrexcel.com/forum/excel...xact-scaleheight-scalewidth-height-width.html

Actual code
Code:
Private Sub cmdView_Click()

Dim sFilename As String
Dim View_Sht As Excel.Worksheet
Dim fpath As String ',
Dim picPath As String, pic As Picture

With ThisWorkbook.Sheets("FileNames")
       fpath = .Range("A3").value & ":\" & .Range("B3").value & "\" & .Range("C3").value & "\"
       sFilename = "InvQt.xlsx"

If AlreadyOpen(sFilename) Then
   MsgBox "Closing " & sFilename
   Set View_Sht = wbk.Worksheets("View InvQt")
   View_Sht.Activate
End If
 End With


picPath = "C:\ImgFolder\" & "1.jpg"
    Dim s As Object
    Dim rr1 As Range: Set rr1 = View_Sht.Range("A1:J1") 'ActiveCell
 Set s = ActiveSheet.Shapes.AddPicture2(picPath, False, True, rr1.Left + 48.48, rr1.Top + 11, 60.0944882, 462.047244, msoPictureCompressTrue) 
   s.LockAspectRatio = False
    s.ScaleHeight Factor:=1, RelativeToOriginalSize:=True
    s.ScaleWidth Factor:=0.93, RelativeToOriginalSize:=True
    
    s.LockAspectRatio = True
    Set s = Nothing
    Set rr1 = Nothing
End Sub

Public Function AlreadyOpen(sFname As String) As Boolean
    Dim wkb As Workbook 
    On Error Resume Next
    Set wkb = Workbooks(sFname)
    AlreadyOpen = Not wkb Is Nothing
    Set wkb = Nothing
End Function
NimishK
 
Last edited:

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Hello

When inserting Images i get Error "variable not defined" using the below code in Excel 2010 but runs perfectly in Excel 2013 which i am currently using

Code:
Set s = ActiveSheet.Shapes.AddPicture2(picPath, False, True, rr1.Left + 48.48, rr1.Top + 11, 60.0944882, 462.047244, msoPictureCompressTrue)

error is highlited onmsoPictureCompressTrue
So any guidance will be appreciated to prevent the above error and coding to run smoothly in all versions of Excel

The utopia of the systems is that the codes work in all the versions.
The new versions like the 2013 try to have all the functions of the previous versions plus the new functions.
But the previous versions can not have all the improvements, since they simply did not exist.


Review the following solution that was applied for the 2010 version.

https://www.mrexcel.com/forum/excel...ng-resize-image-before-inserting-comment.html
 
Upvote 0
I'm glad to help you. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,968
Messages
6,122,506
Members
449,089
Latest member
RandomExceller01

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top