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
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
NimishK
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
Last edited: