當前位置:編程學習大全網 - 編程軟體 - VBA編程中的顏色變換

VBA編程中的顏色變換

1.首先請到網上下個VBA timer 控件並把裏面的“.ocx”文件放到C盤-windows-system32文件夾下,然後開始-運行-“regsvr32 VBAtimer.ocx”-確定(註:這裏假設妳下的的OCX文件名為“VBAtimer.ocx”)。

2.然後打開excel,按照妳自己的要求建立窗體,然後在工具欄上點右鍵-“附加控件”-找到剛剛裝的VBAtimer控件然後在窗體任意地方畫壹個timer控件。

3.然後在新建的窗體上右鍵-“查看代碼”,並輸入以下代碼:

Private Sub CommandButton1_Click()

UserForm1.Label1.Font.Bold = True

UserForm1.Label1.Font.Italic = True

Timer1.Interval = 500

Timer1.Enabled = True

End Sub

Sub timer1_timer()

Dim a As Long, b As Long, c As Long

Randomize

a = Int(256 * Rnd )

b = Int(256 * Rnd )

c = Int(256 * Rnd )

UserForm1.Label1.ForeColor = RGB(a, b, c)

End Sub

Private Sub CommandButton2_Click()

UserForm1.Label1.Font.Bold = False

UserForm1.Label1.Font.Italic = False

Timer1.Enabled = False

End Sub

4.最後在在工程管理窗口上雙擊Thisworkbook,在彈出的代碼框輸入以下代碼:

Private Sub Workbook_Open()

UserForm1.Show

End Sub

5.附:如果2、3、4步不知道做的話,做完第壹步然後把郵箱留給我。

  • 上一篇:關於哈工大(威海)數學系畢業情況
  • 下一篇:我想成為電腦工程師 英語作文
  • copyright 2024編程學習大全網