?前言
前邊兩章學(xué)了直線(xiàn)的畫(huà)法绘梦,那么其他的圖形如何畫(huà)呢?其實(shí)非常簡(jiǎn)單赴魁,既然我們?cè)矶紩?huì)了卸奉,現(xiàn)在就差一個(gè)表達(dá)式了。
?原理
圖形的表達(dá)式和直線(xiàn)稍有不同,不再用兩個(gè)端點(diǎn)的坐標(biāo)表示尚粘,而是用起點(diǎn)坐標(biāo)和長(zhǎng)寬來(lái)表示择卦。其實(shí)都是一樣的,既然我們知道兩個(gè)端點(diǎn)的坐標(biāo)郎嫁,那么長(zhǎng)度不就是兩個(gè)端點(diǎn)的橫坐標(biāo)之差嗎秉继?
Activesheet.AddShape 類(lèi)型, X, Y, Width, Height?
類(lèi)型是指你想要畫(huà)什么圖形,可以用下面的字符串表示泽铛,也可以直接寫(xiě)數(shù)字尚辑。下面為幾個(gè)常用的類(lèi)型。
橢圓:msoShapeOval = 9
矩形:msoShapeRectangle = 1
右箭頭:msoShapeRightArrow = 33
下箭頭:msoShapeDownArrow = 36
五角星:msoShape5pointStar = 92
?單系列
還是拿我們第一次的簡(jiǎn)化實(shí)例盔腔,重新下一遍杠茬,這次畫(huà)一個(gè)矩形月褥,代碼如下:
Sub drawlineR2()
For i = 2 To 4
? ? start_x = Cells(i, Cells(i, 4)).Left
? ? Start_y = Cells(i, Cells(i, 4)).Top + Rows(i).Height / 3
? ? finish_x = Cells(i, Cells(i, 5)).Left + Cells(i, Cells(i, 5)).Width
? ? W = finish_x - start_x
? ? H = Rows(i).Height / 3
? ? ActiveSheet.Shapes.AddShape(1, start_x, Start_y, W, H).Select
Next
End Sub
?多系列
多個(gè)系列,如果日期有重疊瓢喉,請(qǐng)合理設(shè)置每個(gè)系列的位置和高度宁赤,使之錯(cuò)開(kāi)一點(diǎn)的間距,否則會(huì)重疊在一起栓票,最好使用不同的填充色决左,這樣對(duì)比更明顯,如下圖所示:
代碼如下:
Sub drawlineR3()
For i = 2 To 4
'系列一
? ? start_x = Cells(i, Cells(i, 6)).Left
Start_y = Cells(i, Cells(i, 6)).Top +?Rows(i).Height / 4
? ? finish_x = Cells(i, Cells(i, 7)).Left + Cells(i, Cells(i, 7)).Width
? ? Finish_y = Start_y
? ? W = finish_x - start_x
H =?Rows(i).Height / 4
? ? ActiveSheet.Shapes.AddShape(1, start_x, Start_y, W, H).Select
? ? Selection.ShapeRange.Fill.ForeColor.RGB = vbRed
'系列二
? ? start_x = Cells(i, Cells(i, 8)).Left
Start_y = Cells(i, Cells(i, 8)).Top +?Rows(i).Height / 2
? ? finish_x = Cells(i, Cells(i, 9)).Left + Cells(i, Cells(i, 9)).Width
? ? Finish_y = Start_y
? ? W = finish_x - start_x
H =?Rows(i).Height / 4
? ? ActiveSheet.Shapes.AddShape(1, start_x, Start_y, W, H).Select
Next
End Sub
?里程碑
大家知道里程碑只是一個(gè)點(diǎn)走贪,所以只要一個(gè)日期就可以了佛猛,寬度和高度大家可以根據(jù)所在的單元格進(jìn)行調(diào)整,確保在單元格的中心位置就可以了坠狡。
代碼如下:
Sub drawlineR4()
For i = 2 To 4
'里程碑1
start_x = Cells(i, Cells(i, 4)).Left +?Cells(i, Cells(i, 4)).Width / 3
Start_y = Cells(i, Cells(i, 4)).Top +?Rows(i).Height / 3
W =?Cells(i, Cells(i, 4)).Width / 3
H =?Rows(i).Height / 3
ActiveSheet.Shapes.AddShape(36, start_x, Start_y, W, H).Select
? ? Selection.ShapeRange.Fill.ForeColor.RGB = vbRed
'里程碑2
? ?start_x = Cells(i, Cells(i, 5)).Left + Cells(i, Cells(i, 5)).Width / 3
? ? Start_y = Cells(i, Cells(i, 5)).Top + Rows(i).Height / 3
? ? W = Cells(i, Cells(i, 5)).Width / 3
? ? H = Rows(i).Height / 3
ActiveSheet.Shapes.AddShape(92, start_x, Start_y, W, H).Select
? ? Selection.ShapeRange.Fill.ForeColor.RGB = vbRed
Next
End Sub
總結(jié)
線(xiàn)表計(jì)劃你學(xué)會(huì)了嗎继找?有問(wèn)題,歡迎在下方留言逃沿!