表格中的批量复选框
不清楚你要求加复选框的位置是窗体还是表格,这里只给你发个表格里代码:
Dim i As Long
Dim sheetCheckbox1 As CheckBox
' 表格中批量加表格控件
With ActiveSheet
For i = 1 To 10
.Rows(i).RowHeight = 25
.Range("A" &i).Select
Set sheetCheckbox1 = .CheckBoxes.Add(8.4, Selection.top + 2, 100, 18)
sheetCheckbox1.Caption = "表格控件复选框" &i
Next i
' 表格中批量加窗体控件
For i = 1 To 10
.Rows(i).RowHeight = 25
.Range("A" &i).Select
ActiveSheet.OLEObjects.Add(ClassType:="Forms.CheckBox.1", _
Link:=False, DisplayAsIcon:=False, _
left:=Selection.left + Selection.Width, _
top:=25 * (i - 1) + 1, _
Width:=108, _
Height:=18).Select
'没找到如何改控件的标题方法
Next i
End With
方法中的参数.CheckBoxes.Add(left, top, width, height)中分别代表控件的位置左、上、尺寸的宽、高;
方法中的参数.OLEObjects.Add(ClassType,Link,DisplayAsIcon,left,rop,width,height)相应也是有位置、宽高的几个参数,用法接近。
1:在第一个单元格插入复选框后拖动复制。2:如果单元格区域不规则可以用下面代码:
Private Sub AddCheckBoxesInRange()
On Error Resume Next
Dim cell As Range
Dim CurrentRange As Range
Set CurrentRange = Selection
CurrentRange.NumberFormatLocal = ""
Application.ScreenUpdating = False
For Each cell In CurrentRange
ActiveSheet.CheckBoxes.Add(cell.Left, cell.Top, cell.Height, cell.Height).Select
With Selection
.Value = xlOff
.LinkedCell = cell.Address
.Display3DShading = False
.Characters.Text = ""
End With
Next
CurrentRange.Select
Application.ScreenUpdating = True
Set cell = Nothing
End Sub
只要一句代码?那就给你一句参考一下吧:picCount = ActiveDocument.InlineShapes.Count '计算文件中图片数目在Word中,插入的图片已被转化为 InlineShape 对象。之后用For循环语句,给所有图片加黑色边框。单个图片加边框的语句,你自己可以录制一个宏看看,将录制的宏代码拷贝到For循环中修改一下即可。___________________________________________________________________
单个图片加边框,你自己录制宏就可以看到代码了,这是学习VBA的必由之路啊。选中一张图片,工具-宏-录制新宏,然后,格式-边框和阴影,给图片加上黑边框,然后,alt+F11打开VB编译器,就看到代码了。本想只授人以渔即足够了,但犹豫了一下,还是贴给你吧:
With Selection.InlineShapes(1)
With .Borders(wdBorderLeft)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth050pt
.Color = wdColorAutomatic
End With
With .Borders(wdBorderRight)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth050pt
.Color = wdColorAutomatic
End With
With .Borders(wdBorderTop)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth050pt
.Color = wdColorAutomatic
End With
With .Borders(wdBorderBottom)
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth050pt
.Color = wdColorAutomatic
End With
.Borders.Shadow = False
End With
With Options
.DefaultBorderLineStyle = wdLineStyleSingle
.DefaultBorderLineWidth = wdLineWidth050pt
.DefaultBorderColor = wdColorAutomatic
End With
计算图片数目是为了For循环用的,有多少图片就要循环多少次,给所有图片都加上边框。
For i = 1 to picCount
......
Next i
中间就是上面那段代码,把InlineShapes(1)改为InlineShapes(i)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)