VBA add image in cell gives different results

Viewed 55

I have a question about a problem that I can't seem to solve. I have some VBA-code that includes a picture in a cell:

fNameAndPath = UserForm1.ComboBox2.Value

Set img = Application.ActiveSheet.Shapes.AddPicture(fNameAndPath, False, True, 1, 1, 1, 1)
    
    With img

        .Left = ActiveSheet.Range("G" & Lastrow).Left
       .Top = ActiveSheet.Range("G" & Lastrow).Top
       .Width = ActiveSheet.Range("G" & Lastrow).Width
       .Height = ActiveSheet.Range("G" & Lastrow).Height
       .Placement = 1
    
       
    End With 

This code runs perfectly for myself. The pictures are beautifully inserted. However, 20% of my colleagues who use the macro find their picture in column H instead of column G.

I cannot come up with a reason why this happens. Someone who encountered a related issue?

Thank you

1 Answers

Sorry for the delay, hereby the whole code that is in this macro.

Sub CommandButton3_Click()
‘ check whether conditions are OK
If UserForm1.TextBox1.Value = "" Or UserForm1.TextBox2.Value = "" Or UserForm1.TextBox3.Value = "" Or UserForm1.ComboBox1.Value = "" Then
MsgBox ("")
Exit Sub
End If
‘Check whether a picture was attached
If UserForm1.ComboBox2.Value = "" Then
MsgBox ("")
Exit Sub
End If
Workbooks("").Sheets("").Unprotect ""

‘Find username of the user
Dim username As String
username = Environ("username")

‘define lastrow and write some data in the cells
Lastrow = Worksheets("Objets Inutiles").Range("A650000").End(xlUp).Row + 1
Worksheets("Objets Inutiles").Range("A" & Lastrow).Value = "=Now()"
Worksheets("Objets Inutiles").Range("A" & Lastrow).Select
Selection.Copy
Worksheets("Objets Inutiles").Range("A" & Lastrow).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Worksheets("Objets Inutiles").Range("B" & Lastrow).Value = ""
Worksheets("Objets Inutiles").Range("C" & Lastrow).Value = username
Worksheets("Objets Inutiles").Range("C" & Lastrow).Select
Selection.Copy
Worksheets("Objets Inutiles").Range("C" & Lastrow).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Worksheets("Objets Inutiles").Range("D" & Lastrow).Value = UserForm1.ComboBox1.Value
Worksheets("Objets Inutiles").Range("E" & Lastrow).Value = UserForm1.TextBox2.Value
Worksheets("Objets Inutiles").Range("F" & Lastrow).Value = UserForm1.TextBox3.Value
Worksheets("Objets Inutiles").Range("H" & Lastrow).Value = UserForm1.TextBox1.Value
Worksheets("Objets Inutiles").Range("I" & Lastrow).Value = ""
Worksheets("Objets Inutiles").Range("J" & Lastrow).Value = ""

fNameAndPath = UserForm1.ComboBox2.Value

Set img = Application.ActiveSheet.Shapes.AddPicture(fNameAndPath, False, True, 1, 1, 1, 1)
    
    With img
       'Resize Picture to fit in the range....
        .Left = ActiveSheet.Range("G" & Lastrow).Left
       .Top = ActiveSheet.Range("G" & Lastrow).Top
       .Width = ActiveSheet.Range("G" & Lastrow).Width
       .Height = ActiveSheet.Range("G" & Lastrow).Height
       .Placement = 1
           
    End With
   ‘send some spam around

Dim EmailApp As Outlook.Application
Dim Source As String
Set EmailApp = New Outlook.Application
Dim EmailItem As Outlook.MailItem
Set EmailItem = EmailApp.CreateItem(olMailItem)
EmailItem.To = ""
EmailItem.CC = ""
EmailItem.BCC = ""
EmailItem.Subject = ""
EmailItem.HTMLBody = ""

EmailItem.Send
Unload UserForm1
Workbooks("").Sheets("").Protect ""
Workbooks("").Save
MsgBox ("")
Exit Sub
Unload Me
Workbooks("").Sheets("").Protect "Sapore"
Workbooks("").Save
MsgBox ("")
End Sub
Related