Hi,
i made a macro by clicking the cell and inserting a picture image. But, the vba range and the sheet range doesn't match.
ex. i want to insert a picture in cell b6 but it seems the picture inserts in between b5 and b6.
this is my code below
Private Sub Worksheet_BeforeDoubleClick(ByVal target As Range, cancel As Boolean)
If Not Application.Intersect(target, Range("b6")) Is Nothing Then
cancel = True
Dim a As String
Dim img As Object
a = Application.GetOpenFilename("画像,*.jpg", , "画像ファイルの選択")
If a = "false" Then Exit Sub
Set img = ActiveSheet.Shapes.AddPicture(Filename:=a, linktofile:=False, savewithdocument:=True, Left:=0, Top:=0, Width:=-1, Height:=-1)
With img
'Move and Resize Image
img.Select
Selection.ShapeRange.LockAspectRatio = msoFalse
Selection.Left = ActiveSheet.Range("b6").Left
Selection.Top = ActiveSheet.Range("b6").Top
Selection.Width = ActiveSheet.Range("b6:e6").Width
Selection.Height = ActiveSheet.Range("b6:b16").Height
End With
End If
end sub
it is supposed to be inserting on cell B6.
please help me. thanks
p.s. please ignore the japanese characters
i made a macro by clicking the cell and inserting a picture image. But, the vba range and the sheet range doesn't match.
ex. i want to insert a picture in cell b6 but it seems the picture inserts in between b5 and b6.
this is my code below
Private Sub Worksheet_BeforeDoubleClick(ByVal target As Range, cancel As Boolean)
If Not Application.Intersect(target, Range("b6")) Is Nothing Then
cancel = True
Dim a As String
Dim img As Object
a = Application.GetOpenFilename("画像,*.jpg", , "画像ファイルの選択")
If a = "false" Then Exit Sub
Set img = ActiveSheet.Shapes.AddPicture(Filename:=a, linktofile:=False, savewithdocument:=True, Left:=0, Top:=0, Width:=-1, Height:=-1)
With img
'Move and Resize Image
img.Select
Selection.ShapeRange.LockAspectRatio = msoFalse
Selection.Left = ActiveSheet.Range("b6").Left
Selection.Top = ActiveSheet.Range("b6").Top
Selection.Width = ActiveSheet.Range("b6:e6").Width
Selection.Height = ActiveSheet.Range("b6:b16").Height
End With
End If
end sub
it is supposed to be inserting on cell B6.
please help me. thanks
p.s. please ignore the japanese characters