Excel 雙斜線表頭繪制
在子產品中添加以下方法:
Sub 雙斜線表頭()
Dim sht As Worksheet
Dim rng As Range
Dim line1 As Shape
Dim line2 As Shape
Dim txt1 As Shape
Dim txt2 As Shape
Dim txt3 As Shape
Set sht = ActiveSheet
Set rng = ActiveCell
Set line1 = sht.Shapes.AddLine(rng.Left + rng.Width / , rng.Top, rng.Left + rng.Width, rng.Top + rng.Height)
Set line2 = sht.Shapes.AddLine(rng.Left, rng.Top + rng.Height / , rng.Left + rng.Width, rng.Top + rng.Height)
line1.ShapeStyle = msoLineStylePreset1
line2.ShapeStyle = msoLineStylePreset1
Set txt1 = sht.Shapes.AddTextbox(msoTextOrientationHorizontal, rng.Left, rng.Top, rng.Width / , rng.Height / )
Set txt2 = sht.Shapes.AddTextbox(msoTextOrientationHorizontal, rng.Left + rng.Width / * , rng.Top, rng.Width / * , rng.Height / )
Set txt3 = sht.Shapes.AddTextbox(msoTextOrientationHorizontal, rng.Left, rng.Top + rng.Height / * , rng.Width / , rng.Height / )
txt1.Fill.Visible = msoFalse
txt2.Fill.Visible = msoFalse
txt3.Fill.Visible = msoFalse
txt1.Line.Visible = msoFalse
txt2.Line.Visible = msoFalse
txt3.Line.Visible = msoFalse
txt1.TextFrame2.TextRange.Text = "銷量"
txt2.TextFrame2.TextRange.Text = "産品"
txt3.TextFrame2.TextRange.Text = "月份"
sht.Shapes.Range(Array(line1.Name, line2.Name, txt1.Name, txt2.Name, txt3.Name)).Group
End Sub
選中單元格,運作代碼,效果如圖: