View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.office.developer.automation,microsoft.public.access
Dale Fye Dale Fye is offline
external usenet poster
 
Posts: 169
Default Visually represent project dates and activities as shapes in Excel

Actually, this turns out to be relatively simple; the key is knowing what
cells you want to draw the lines or boxes between, which is trivial really.

1. Each cell has .Left, .Top, .Width and .Height properties, so to
determine the start and end points of the line/box you use something like:

Set sht = xlApp.ActiveWorksheet
lngLineLeft = sht.Cells(intRow, intStartCol).Left
lngLineRight = sht.Cells(intRow, intEndCol).Left + sht.Cells(intRow,
intEndCol).Width

Same sort of thing for getting the top and bottom position of the line or
box you want to draw

2. Then you use the one of the Shapes.AddXXXX methods to add the shape to
that position on the spreadsheet. Below, I've listed the code I used to add
a line, a box. Additionally, since I wanted a mouseover or control tip text
type capability, I also added hyperlinks (that go nowhere)

With sht.Shapes.AddLine(lngLineLeft, lngLineCenter, lngLineRight,
lngLineCenter).Line
.Weight = 3
.DashStyle = msoLineSolid
.ForeColor.RGB = RGB(128, 128, 128)
End With

If IsNull(TipText) = False Then
sht.Hyperlinks.Add sht.Shapes(sht.Shapes.Count), "", "", TipText
End If

Set shpBox = sht.Shapes.AddShape(msoShapeRound1Rectangle, lngBoxLeft,
lngBoxTop, lngBoxRight - lngBoxLeft, 15)
With shpBox
.Fill.BackColor.RGB = RGB(121, 121, 113)
.Fill.Transparency = 0.5

sht.Hyperlinks.Add shpBox, "", "", "Place your hyperlink text here"

End With

3. Lastly, I wanted to be able to associate a label with each of the boxes,
so I used the code below:

Set shpLabel = sht.Shapes.AddTextbox(msoTextOrientationHorizontal ,
lngBoxLeft, lngBoxTop + 9, lngBoxRight - lngBoxLeft, 15)
With shpLabel
.TextEffect.Text = IIf(Milestone = "Event dates", "Main event",
Milestone)
.TextFrame.AutoSize = True
.TextEffect.FontBold = msoTrue
.TextEffect.FontSize = 10
End With

Hope this helps the next guy that wants to try something like this.

Dale