Tôi có sử dụng đoạn code để tự động chạy shapes (Thanh gạch chéo dưới phiếu xuất)
Private Sub Worksheet_Change(ByVal Target As Range)
Dim shp As Shape 'xoa duong cu
Me.Unprotect Password:="12480"
For Each shp In ActiveSheet.Shapes
If shp.Name Like "*Straight*" Then
shp.Delete
End If
tieptheo:
Next shp
'them duong moi
endr = Range("F100").End(xlUp).Row
For i = 24 To endr
tempt = Cells(i, 8).Value
If tempt = "" Then
stt = i
Exit For
End If
Next
Set rngStart = Range("E" & stt)
Set rngEnd = Range("H35")
BX = rngStart.Left
BY = rngStart.Top
EX = rngEnd.Left + rngEnd.Width
EY = rngEnd.Top
With ActiveSheet.Shapes.AddLine(BX, BY + 2, EX, EY + 0).Line
.ForeColor.RGB = vbRed
.Weight = 1#
End With
Me.Protect Password:=" 12480", AllowFormattingColumns:=True, AllowFormattingRows:=True, AllowFormattingCells:=True, AllowFormattingObjects:=True
End Sub
nhưng khi chạy bị lỗi đoạn code : AllowFormattingObjects:=True
Xin các bạn trợ giúp - Trân trọng cảm ơn !
Private Sub Worksheet_Change(ByVal Target As Range)
Dim shp As Shape 'xoa duong cu
Me.Unprotect Password:="12480"
For Each shp In ActiveSheet.Shapes
If shp.Name Like "*Straight*" Then
shp.Delete
End If
tieptheo:
Next shp
'them duong moi
endr = Range("F100").End(xlUp).Row
For i = 24 To endr
tempt = Cells(i, 8).Value
If tempt = "" Then
stt = i
Exit For
End If
Next
Set rngStart = Range("E" & stt)
Set rngEnd = Range("H35")
BX = rngStart.Left
BY = rngStart.Top
EX = rngEnd.Left + rngEnd.Width
EY = rngEnd.Top
With ActiveSheet.Shapes.AddLine(BX, BY + 2, EX, EY + 0).Line
.ForeColor.RGB = vbRed
.Weight = 1#
End With
Me.Protect Password:=" 12480", AllowFormattingColumns:=True, AllowFormattingRows:=True, AllowFormattingCells:=True, AllowFormattingObjects:=True
End Sub
nhưng khi chạy bị lỗi đoạn code : AllowFormattingObjects:=True
Xin các bạn trợ giúp - Trân trọng cảm ơn !