|
楼主 |
发表于 2013-6-24 13:11
|
显示全部楼层
本帖最后由 sdada 于 2013-6-24 22:11 编辑
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.CommandBars(1).Reset
Open Application.Path & "\Select.txt" For Output As #1
Print #1, b(0)
Print #1, b(1)
Close #1
End Sub
Private Sub Workbook_Open()
Dim mFile As String, mStr2 As String, mStr
mFile = Application.Path & "\Select.txt"
If Dir(mFile) <> "" Then
Open mFile For Input As #1
Do Until EOF(1)
Line Input #1, mStr
If mStr2 = "" Then mStr2 = mStr Else mStr2 = mStr2 + vbNewLine + mStr
Loop
Close #1
mStr = Split(mStr2, vbNewLine)
b(0) = Val(mStr(0))
b(1) = Val(mStr(1))
Else
b(0) = 5
b(1) = 5
End If
With Application.CommandBars(1)
.Reset
With .Controls.Add(Type:=msoControlPopup)
.Caption = "测试"
Set a(0) = .Controls.Add(Type:=msoControlButton)
With a(0)
.Caption = "按钮1"
.OnAction = "aaa"
.Enabled = (b(0) <> 0)
End With
Set a(1) = .Controls.Add(Type:=msoControlButton)
With a(1)
.Caption = "按钮2"
.OnAction = "bbb"
.Enabled = (b(1) <> 0)
End With
With .Controls.Add(Type:=msoControlButton)
.Caption = "恢复"
.OnAction = "ccc"
End With
End With
End With
End Sub
Public a(1) As CommandBarControl, b(1) As Integer
Sub aaa()
b(0) = b(0) - 1
MsgBox "你好:" & Chr(10) & "还有:" & b(0) & "使用次数"
If b(0) = 0 Then a(0).Enabled = False
End Sub
Sub bbb()
b(1) = b(1) - 1
MsgBox "欢迎:" & Chr(10) & "还有:" & b(1) & "使用次数"
If b(1) = 0 Then a(1).Enabled = False
End Sub
Sub ccc()
b(0) = 5
b(1) = 5
a(0).Enabled = True
a(1).Enabled = True
End Sub
|
|