chatGPT ¤H¤u´¼¼z¥i¥HÀ°§A½m²ßVBAµ{¦¡
´X¬íÄÁ¼g¥Xµ{¦¡¯uªº¥i¥Î¡A§Ú¥u¥[¤F On Error Resume Next ×¥¿¿ù»~
https://openai.com/blog/chatgpt
chatGPT¸ß°Ý¦p¤U¡G
¦bEXCEL¸Ì±¥ÎVBAµ{¦¡Ã¸¥X°ÊºA¶ê§Î®ÉÄÁ
chatGPT¦^ÂЦp¤U¡G
¥H¤U¬O¤@Ó²³æªºVBAµ{¦¡¡A¥i¥H¦bExcel¤¤Ã¸»s¤@ӰʺAªº¶ê§Î®ÉÄÁ¡G
Sub DrawClock()
Dim i As Integer
Dim j As Integer
Dim r As Integer
Dim pi As Double
Dim ang As Double
Dim x As Double
Dim y As Double
'³]©w¶ê¤ß®y¼Ð¤Î¥b®|
r = 100
x = 150
y = 150
'¨ú±o·í«e®É¶¡
h = Hour(Now)
m = Minute(Now)
s = Second(Now)
'²M°£Â®ÉÄÁ
On Error Resume Next '¨¾¤î²Ä¤@¦¸¨S¦³¸ê®Æ¥i§R·|¿ù»~¤¤Â_
ActiveSheet.Shapes.Range(Array("Clock")).Delete
'ø»s®ÉÄÁ¶ê§Î
Set myshape = ActiveSheet.Shapes.AddShape(msoShapeOval, x - r, y - r, 2 * r, 2 * r)
myshape.Name = "Clock"
myshape.Line.ForeColor.RGB = RGB(0, 0, 0)
'ø»s®ÉÄÁ¨è«×
pi = 3.14159265359
For i = 1 To 12
ang = pi / 6 * (i - 3)
x1 = x + r * Cos(ang)
y1 = y + r * Sin(ang)
x2 = x + (r - 10) * Cos(ang)
y2 = y + (r - 10) * Sin(ang)
Set myshape = ActiveSheet.Shapes.AddLine(x1, y1, x2, y2)
myshape.Line.Weight = 2
myshape.Line.ForeColor.RGB = RGB(0, 0, 0)
Next i
'ø»s®É°w
ang = pi / 6 * (h - 3) + pi / 360 * m + pi / 21600 * s
x1 = x
y1 = y
x2 = x + (r - 50) * Cos(ang)
y2 = y + (r - 50) * Sin(ang)
Set myshape = ActiveSheet.Shapes.AddLine(x1, y1, x2, y2)
myshape.Line.Weight = 4
myshape.Line.ForeColor.RGB = RGB(255, 0, 0)
'ø»s¤À°w
ang = pi / 30 * (m - 15) + pi / 1800 * s
x1 = x
y1 = y
x2 = x + (r - 30) * Cos(ang)
y2 = y + (r - 30) * Sin(ang)
Set myshape = ActiveSheet.Shapes.AddLine(x1, y1, x2, y2)
myshape.Line.Weight = 3
myshape.Line.ForeColor.RGB = RGB(0, 255, 0)
'ø»s¬í°w
ang = pi / 30 * (s - 15)
x1 = x
y1 = y
x2 = x + (r - 20) * Cos(ang)
y2 = y + (r - 20) * Sin(ang)
Set myshape = ActiveSheet.Shapes.AddLine(x1, y1, x2, y2)
myshape.Line.Weight = 1.5
myshape.Line.ForeColor.RGB = RGB(0, 0, 255)
End Sub |