|
楼主 |
发表于 2009-8-23 21:01
|
显示全部楼层
原帖由 nyafullee 于 2009-8-14 17:19 发表
第三方案是采用宏中宏的方式,但是,遗憾的是,非要两次点出按钮
Sub VBA_43()
'By nyafullee
Dim rows_line%, i%, s$, ss$, exit_nya As Boolean
exit_nya = ThisWorkbook.VBProject.VBComponents("模块1").CodeModule.Find("Public Sub nyafullee", 70, 1, 10000, 1, False , False )
If exit_nya = False Then
top_c6 = Sheet1.Range("c6").Top: top_f6 = Sheet1.Range("f6").Top: s = "CheckBox"
For i = 1 To 8
ss = ss & "," & s & i + 8
Next
ss = Right(ss, Len(ss) - 1)
Sheet1.Shapes(9).Ungroup
With ThisWorkbook.VBProject.VBComponents("模块1")
rows_line = .CodeModule.CountOfLines + 5
.CodeModule.InsertLines rows_line, "public sub nyafullee()"
rows_line = .CodeModule.CountOfLines + 1
.CodeModule.InsertLines rows_line, "dim top_c6#,top_f6#,s$": rows_line = .CodeModule.CountOfLines + 1
.CodeModule.InsertLines rows_line, "top_c6 = Sheet1.Range(""c6"").Top: top_f6 = Sheet1.Range(""f6"").Top"
rows_line = .CodeModule.CountOfLines + 1
'''''''''''''''''''''''''''''''''''''
For i = 1 To 16
.CodeModule.InsertLines rows_line, "sheet1." & s & i & ".Height=27:sheet1." & s & i & ".Caption=sheet1." & s & i & ".name:" & _
"sheet1." & s & i & ".LinkedCell=sheet1.range(""iv" & i & """).address(0,0):" & _
"sheet1." & s & i & ".value=not sheet1." & s & i & ".value"
rows_line = .CodeModule.CountOfLines + 1
Next
'''''''''''''''''''''''''''''''''''''
For i = 1 To 16
If i < 9 Then
.CodeModule.InsertLines rows_line, "sheet1." & s & i & ".left=108:sheet1." & s & i & ".top =top_c6 + " & (i - 1) * 27
rows_line = .CodeModule.CountOfLines + 1
Else
.CodeModule.InsertLines rows_line, "sheet1." & s & i & ".left=270:sheet1." & s & i & ".top =top_f6 + " & (i - 9) * 27
rows_line = .CodeModule.CountOfLines + 1
End If
Next
'''''''''''''''''''''''''''''''''''''
For i = 1 To 16
Select Case i Mod 3
Case 1
.CodeModule.InsertLines rows_line, "sheet1." & s & i & ".forecolor=&HFF&"
rows_line = .CodeModule.CountOfLines + 1
Case 2:
.CodeModule.InsertLines rows_line, "sheet1." & s & i & ".forecolor=&HFF0000"
rows_line = .CodeModule.CountOfLines + 1
Case 0
.CodeModule.InsertLines rows_line, "sheet1." & s & i & ".forecolor=&HFFFF00"
rows_line = .CodeModule.CountOfLines + 1
End Select
Next
'''''''''''''''''''''''''''''''''''
.CodeModule.InsertLines rows_line, "g": rows_line = .CodeModule.CountOfLines + 1
.CodeModule.InsertLines rows_line, "end sub"
End With
''''''''''
MsgBox "已经生成相应的代码!!!" & vbCrLf & vbCrLf & "请继续点击""试一试按钮""!!!" & vbCrLf & vbCrLf & "以查看此代码产生的变化!!"
Else
Application.Run "nyafullee"
End If
End Sub
Sub g()
Dim arr(1 To 8), s$, i%, a#, b#
s = "CheckBox"
For i = 1 To 8
arr(i) = s & i + 8
Next
Sheet1.Shapes.Range(arr).Group
With ThisWorkbook.VBProject.VBComponents("模块1").CodeModule
a = .ProcCountLines("nyafullee", vbext_pk_Proc)
b = .ProcBodyLine("nyafullee", vbext_pk_Proc)
.DeleteLines b, a
End With
End Sub
老朽意见:纵观选手的三种方案,无一例外的均使用了绝对数值来设置控件的高度、左边距、顶边距,用选手的话说就是为了确保与原始效果图一致。
三种方案均能满足要求,并且增加了一个图片实时显示各控件LinkedCell的值,这是一个比较新颖的做法,值得学习。
最后一种方案,采用实时添加宏的办法,有点遗憾,设计不够完美,有待继续研究。
综上所述:三种方案基本满足要求,建议版主加分。
[ 本帖最后由 zldccmx 于 2009-8-23 21:12 编辑 ] |
|