【 学点VBA之EXCEL 】二

(1)在VBA中创建一个窗体,初始化其位置,并调用之...

 

Sub CallForm()
UserForm1.Show
'显示窗体
UserForm1.Left = 600 '显示位置
UserForm1.Top = 180
End Sub


Private Sub CommandButton1_Click()
CallForm
'调用
End Sub

 

 

(2)Excel的单元格的字体颜色、单元格的背景颜色


代码
Private Sub CommandButton1_Click()
Dim i, j, k As Integer
j
= 0
k
= 0
l
= 0
m
= 0

For i = 1 To 10

If Cells(i, 1).Font.Color = 0 Then '判断字体颜色为黑色
j = j + 1
End If

If Cells(i, 1).Font.Color = 255 Then '判断字体颜色为红色
k = k + 1
End If

If Cells(i, 2).Interior.Color = &HFFFFFF Then '判断背景颜色为白色
l = l + 1
End If

If Cells(i, 2).Interior.Color = &HFF Then '判断背景颜色为红色
m = m + 1
End If

Next i

Dim FC, BC As String

FC
= "Red = " & k & ",Black = " & j
MsgBox (FC)

BC
= "White = " & l & ",Red = " & m
MsgBox (BC)
End Sub

 


posted @ 2010-09-02 13:35  Delcpp  阅读(444)  评论(0编辑  收藏  举报