答案1
这看起来就像 Outlook 日历可以做的事情。
但是,您所描述的是可行的。您将学习一些 VBA 编程。
其中一些看起来像这样,存放类似甘特图的条形图(尚无文字)...
Option Explicit
Sub main()
Call InsertBar(0, 800)
End Sub
Sub InsertBar(LeftStart As Long, TotalWidth As Long)
Dim myWkSht As Worksheet
Dim myShp As Shape
Dim MaxWidth As Long, nBars As Long
Dim bDone As Boolean, iLoop As Long
Dim myStart() As Long, myWidth() As Long
If LeftStart < 0 Then Exit Sub
If TotalWidth <= 0 Then Exit Sub
Set myWkSht = Worksheets("Sheet2")
MaxWidth = myWkSht.Range("O1").Left
bDone = False
nBars = 1
ReDim myStart(1 To nBars)
ReDim myWidth(1 To nBars)
myStart(nBars) = LeftStart
myWidth(nBars) = TotalWidth
Do While Not bDone
If myStart(nBars) + myWidth(nBars) < MaxWidth Then
bDone = True
Else
nBars = nBars + 1
ReDim Preserve myStart(1 To nBars)
ReDim Preserve myWidth(1 To nBars)
myStart(nBars) = 0
myWidth(nBars - 1) = MaxWidth - myStart(nBars - 1)
myWidth(nBars) = TotalWidth - myWidth(nBars - 1)
End If
Loop
For iLoop = 1 To nBars
With myWkSht
Set myShp = .Shapes.AddShape(msoShapeRectangle, _
myStart(iLoop), .Range("A10").Offset((iLoop - 1) * 6, 0).Top, _
myWidth(iLoop), .Range("A10").Offset((iLoop - 1) * 6, 0).Height)
End With
With myShp
.Fill.ForeColor.ObjectThemeColor = msoThemeColorBackground2
.Fill.ForeColor.TintAndShade = 0
.Fill.ForeColor.Brightness = 0
.Fill.Transparency = 0
.Fill.Solid
.Line.ForeColor.ObjectThemeColor = msoThemeColorBackground2
.Line.ForeColor.TintAndShade = 0
.Line.ForeColor.Brightness = 0
.Line.Transparency = 0
End With
Next iLoop
End Sub
我开始的、基本的日历模型是这样的......
...运行示例代码后看起来像这样...