VBA实现在指定的字段区域内选择单元格时插入按钮
需求:VBA实现在指定的字段区域内选择单元格时插入按钮,比如明细表中的一列点击一个单元格时插入一个按钮,点击字段内其他的单元格时,删除其他的按钮。
效果:
方法:
- Public Sub RangeSelection(sender As Object,e As SpreadsheetGear.Windows.Controls.RangeSelectionChangedEventArgs)
- Dim Rng As IRange = e.RangeSelection.Intersect(Range("F_59119"))
- If Not Rng Is Nothing Then
- Dim r As Double = ActiveWorkbook.ActiveWorksheet.WindowInfo.RowToPoints(e.RangeSelection.Row)
- Dim c As Double = ActiveWorkbook.ActiveWorksheet.WindowInfo.ColumnToPoints(e.RangeSelection.Column)
- Dim rw As Double = ActiveWorkbook.ActiveWorksheet.Range(e.RangeSelection.Address).Width
- Dim rh As Double = ActiveWorkbook.ActiveWorksheet.Range(e.RangeSelection.Address).Height
- Dim bw As Integer = 10
- Dim bh As Integer = rh - 4
- For i As Integer = ActiveWorkbook.ActiveWorksheet.Shapes.Count - 1 To 0 Step -1
- If Left(ActiveWorkbook.ActiveWorksheet.Shapes(i).Name, 5) = "List_" Then
- ActiveWorkbook.ActiveWorksheet.Shapes(i).Delete()
- End If
- Next
- ActiveWorkbook.Worksheets("Sheet1").Shapes.AddFormControl(1, c + rw - bw - 2, r + 2, bw, bh).Name = "List_" & e.RangeSelection.Address
- End If
- End Sub'单元格选择后执行的事件
复制代码
|
|
hessen