cần giúp đở đoạn code xóa ảnh trước đó đã Insert

Liên hệ QC

hondacrv2019

Thành viên bị đình chỉ hoạt động
Thành viên bị đình chỉ hoạt động
Tham gia
19/5/19
Bài viết
116
Được thích
9
Em cần 1 đoạn code hiện hình ảnh vào ô B3 ( Vừa khíp với diện tích ở B3 ) khi thay đổi đường dẫn tại ô B1. Code chạy thì Ok mổi tội là nó không xóa ảnh trước đó thành ra nó tạo nhiều hình ảnh. Mong mọi người giúp đở

Mã:
Sub InsertPic()
    Dim PicPath As String, Pic As Picture, ImageCell As Range
    PicPath = Range("b1").Value
    Set ImageCell = Range("b3")
    Set Pic = ActiveSheet.Pictures.Insert(PicPath)
    With Pic
        .ShapeRange.LockAspectRatio = msoFalse
        .Left = ImageCell.Left
        .Top = ImageCell.Top
        .Width = ImageCell.Width
        .Height = ImageCell.Height
    End With
End Sub

217643
 
Lần chỉnh sửa cuối:
Em cần 1 đoạn code hiện hình ảnh vào ô B3 ( Vừa khíp với diện tích ở B3 ) khi thay đổi đường dẫn tại ô B1. Code chạy thì Ok mổi tội là nó không xóa ảnh trước đó thành ra nó tạo nhiều hình ảnh. Mong mọi người giúp đở

Mã:
Sub InsertPic()
    Dim PicPath As String, Pic As Picture, ImageCell As Range
    PicPath = Range("b1").Value
    Set ImageCell = Range("b3")
    Set Pic = ActiveSheet.Pictures.Insert(PicPath)
    With Pic
        .ShapeRange.LockAspectRatio = msoFalse
        .Left = ImageCell.Left
        .Top = ImageCell.Top
        .Width = ImageCell.Width
        .Height = ImageCell.Height
    End With
End Sub

View attachment 217643
Đặt cho nó cái tên rồi xoá là xong à.
 
Upvote 0
Em cần 1 đoạn code hiện hình ảnh vào ô B3 ( Vừa khíp với diện tích ở B3 ) khi thay đổi đường dẫn tại ô B1. Code chạy thì Ok mổi tội là nó không xóa ảnh trước đó thành ra nó tạo nhiều hình ảnh. Mong mọi người giúp đở

Mã:
Sub InsertPic()
    Dim PicPath As String, Pic As Picture, ImageCell As Range
    PicPath = Range("b1").Value
    Set ImageCell = Range("b3")
    Set Pic = ActiveSheet.Pictures.Insert(PicPath)
    With Pic
        .ShapeRange.LockAspectRatio = msoFalse
        .Left = ImageCell.Left
        .Top = ImageCell.Top
        .Width = ImageCell.Width
        .Height = ImageCell.Height
    End With
End Sub

View attachment 217643
Thử sửa lại thế này.
Mã:
Sub InsertPic()
On Error Resume Next
    Dim PicPath As String, Pic As Picture, ImageCell As Range
    PicPath = Range("b1").Value
    Set ImageCell = Range("b3")
    ActiveSheet.Pictures("GPE").Delete
    Set Pic = ActiveSheet.Pictures.Insert(PicPath)
    Pic.Name = "GPE"
    With Pic
        .ShapeRange.LockAspectRatio = msoFalse
        .Left = ImageCell.Left
        .Top = ImageCell.Top
        .Width = ImageCell.Width
        .Height = ImageCell.Height
    End With
End Sub
 
Upvote 0
Thử sửa lại thế này.
Mã:
Sub InsertPic()
On Error Resume Next
    Dim PicPath As String, Pic As Picture, ImageCell As Range
    PicPath = Range("b1").Value
    Set ImageCell = Range("b3")
    ActiveSheet.Pictures("GPE").Delete
    Set Pic = ActiveSheet.Pictures.Insert(PicPath)
    Pic.Name = "GPE"
    With Pic
        .ShapeRange.LockAspectRatio = msoFalse
        .Left = ImageCell.Left
        .Top = ImageCell.Top
        .Width = ImageCell.Width
        .Height = ImageCell.Height
    End With
End Sub

Trời ời mấy bác GPE quá giỏi. Em xin chân thành cảm ơn !
 
Upvote 0
Web KT

Bài viết mới nhất

Back
Top Bottom