Sub CreateShape() Dim shp1 As Shape Dim shp2 As Shape
Set shp1 = ActiveSheet.Shapes.AddShape( _ msoShape16pointStar, _ ActiveCell.Left, _ ActiveCell.Top, 80, 27)
Set shp2 = ActiveSheet.Shapes.AddShape( _ 94, ActiveCell.Left, _ ActiveCell.Top, 80, 27)End Sub









Sub DetermineShapeType()Dim ActiveShape As ShapeDim UserSelection As VariantSet UserSelection = ActiveWindow.SelectionOn Error GoTo NoShapeSelectedSet ActiveShape = ActiveSheet.Shapes(UserSelection.Name)On Error Resume NextMsgBox '所選形狀類(lèi)型:' & ActiveShape.AutoShapeTypeExit SubNoShapeSelected:MsgBox '沒(méi)有選擇形狀!'End Sub

Sub ShapePositionFromCell() Dim shp As Shape
Set shp = ActiveSheet.Shapes.AddShape( _ msoShapeRectangle, _ Range('B1').Left, _ Range('B10').Top, _ 100, 50)End SubSub DetermineShapePosition()Dim ActiveShape As ShapeDim UserSelection As VariantSet UserSelection = ActiveWindow.SelectionOn Error GoTo NoShapeSelectedSet ActiveShape = ActiveSheet.Shapes(UserSelection.Name)On Error Resume NextMsgBox '左側位置: ' & ActiveShape.Left & vbNewLine & _'頂部位置: ' & ActiveShape.TopExit SubNoShapeSelected:MsgBox '沒(méi)有選擇形狀!'End Sub

Sub ShapeSizeFromRange() Dim shp As Shape Dim rng As Range
Set rng = Range('A1:C4')
Set shp = ActiveSheet.Shapes.AddShape(msoShapeRectangle, _ ActiveCell.Left, _ ActiveCell.Top, _ rng.Width, _ rng.Height)End SubSub DetermineShapeSize()Dim ActiveShape As ShapeDim UserSelection As VariantSet UserSelection = ActiveWindow.SelectionOn Error GoTo NoShapeSelectedSet ActiveShape = ActiveSheet.Shapes(UserSelection.Name)On Error Resume NextMsgBox '寬度: ' & ActiveShape.Width & vbNewLine & _'高度: ' & ActiveShape.HeightExit SubNoShapeSelected:MsgBox '沒(méi)有選擇形狀!'End Sub
Sub CreateShapeWithText() Dim shp As Shape
Set shp = ActiveSheet.Shapes.AddShape( _ msoShape16pointStar, _ ActiveCell.Left, _ ActiveCell.Top, _ 160, 60)
'在形狀中添加文本 shp.TextFrame2.TextRange.Text = '完美Excel'
'加粗/斜體/下劃線(xiàn) With shp.TextFrame2.TextRange.Font .Bold = True .Italic = True .UnderlineStyle = msoUnderlineDottedLine
'改變文本顏色 .Fill.ForeColor.RGB = RGB(225, 140, 71) '改變文本大小 .Size = 14 End With
'居中對齊 shp.TextFrame.HorizontalAlignment = xlHAlignCenter shp.TextFrame.VerticalAlignment = xlVAlignCenterEnd SubSub CreateShapeWithBorder()Dim shp As ShapeSet shp = ActiveSheet.Shapes.AddShape( _msoShapeRoundedRectangle, _ActiveCell.Left, _ActiveCell.Top, _80, 27)'填充顏色shp.Fill.ForeColor.RGB = RGB(253, 234, 218)'邊框線(xiàn)條樣式shp.Line.DashStyle = msoLineDashDotDot'邊框顏色shp.Line.ForeColor.RGB = RGB(252, 213, 181)'調整邊框寬度shp.Line.Weight = 2'刪除邊框shp.Line.Visible = FalseEnd Sub
Sub ChangeShapeType() Dim shp As Shape
Set shp = ActiveSheet.Shapes('16-Point Star 6')
shp.AutoShapeType = msoShapeOvalEnd SubSub Create_Button()Dim bttn As ShapeSet bttn = ActiveSheet.Shapes.AddShape( _msoShapeRoundedRectangle, _ActiveCell.Left, _ActiveCell.Top, _80, 27)'修改文本格式With bttn.TextFrame2.TextRange.Text = '執行宏'.Font.Bold = msoTrue.Font.Fill.ForeColor.RGB = RGB(0, 0, 0).Font.Size = 14End With'居中對齊bttn.TextFrame.HorizontalAlignment = xlHAlignCenterbttn.TextFrame.VerticalAlignment = xlVAlignCenter'填充顏色bttn.Fill.ForeColor.RGB = RGB(217, 217, 217)'無(wú)邊框bttn.Line.Visible = msoFalseEnd Sub
Sub ChangeRectangleShapes() Dim shp As Shape
'遍歷當前工作表中所有形狀 For Each shp In ActiveSheet.Shapes '僅修改矩形形狀 If shp.AutoShapeType = msoShapeRectangle Then shp.Fill.ForeColor.RGB = RGB(253, 234, 218) End If Next shpEnd Sub聯(lián)系客服