Sub AnimateHeart

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Sub AnimateHeart()

Dim Heart As Shape

Dim TopTriangle As Shape

Dim BottomCircle As Shape

Dim LeftPos As Single

Dim TopPos As Single

Dim Increase As Single

' Ðat vi tri ban dau hinh trai tim

LeftPos = 100

TopPos = 100

Increase = 1

'Lay hinh ve da tao

Set TopTriangle = ActiveSheet.Shapes("TamGiac")

Set BottomCircle = ActiveSheet.Shapes("Hinhtron")

'Ve trai tim bang cach dat vi tri cua cac hinh

Set Heart = ActiveSheet.Shapes.AddShape(msoShape0val, LeftPos, TopPos, 100, 100)

Heart.Fill.ForeColor.RGB = RGB(255, 0, 0)

Heart.Line.Visible = msoFalse

'Di chuyen trai tim len va xuong

Do While True

TopPos = TopPos + Increase

If TopPos > 200 Or TopPos < 100 Then

Increase = -Increase

End If

Heart.Top = TopPos

DoEvents ' Cho phep trai tim di chuyen troi chay


Application.Wait Now + TimeValue("00:00:01")

Loop

' Macro1 Macro

' Traitim

'

' Keyboard Shortcut: Ctrl+Shift+R

'

End Sub

Sub HeartAnimation()

Dim HeartShape As Shape

Set HeartShape = ThisWorkbook.Sheets("Sheet1").Shapes("HeartShape")

Dim ColorIndex As Integer

ColorIndex = 1

Do

If ColorIndex > 3 Then

ColorIndex = 1

End If

Select Case ColorIndex

Case 1

HeartShape.Fill.ForeColor.RGB = RGB(255, 0, 0) ' Màu đỏ

Case 2

HeartShape.Fill.ForeColor.RGB = RGB(0, 255, 0) ' Màu xanh lá cây

Case 3

HeartShape.Fill.ForeColor.RGB = RGB(0, 0, 255) ' Màu xanh dương


End Select

ColorIndex = ColorIndex + 1

Application.Wait Now + TimeValue("00:00:01") ' Đợi 1 giây trước khi thay đổi màu

Loop

End Sub

You might also like