生成随机激活码
找工具箱
插入按钮
建宏
方法一:新建按钮的时候创建宏
方法二:右键->指定宏
VBA
VBA代码界面 调整字体
VBA代码
vbnet
Public str As String ' 存储激活码显示的字符
Public st As String ' 中间变量,用来替代随机数
Public ot As String ' 显示的激活码
Public i As Integer ' 显示激活码的数量
Public j As Integer ' 激活码长度
Sub 按钮2_Click()
' 允许显示的字符
str = "1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM"
' 循环9次生成9个激活码
For i = 1 To 9
ot = "" ' 每次生成激活码时清空ot
' 循环9次生成每个激活码的9个字符
For j = 1 To 9
' 从1到62中随机生成一个数
m = Application.WorksheetFunction.RandBetween(1, 62)
' 从str中提取第m个字符
st = Mid(str, m, 1)
' 将提取的字符添加到ot中
ot = ot & st
Next j
' 将生成的激活码放入对应的单元格
Cells(1 + i, 2) = ot
Next i
End Sub
vbnet
Sub 按钮2_Click()
str = "1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM"
For i = 1 To 9
ot = ""
For j = 1 To 9
m = Application.RandBetween(1, 62)
st = Mid(str, m, 1)
ot = ot & st
If j = 9 Then Cells(1 + i, 2) = ot
Next
Next i
End Sub
效果
创建加减血条
血条颜色(自定义设置表格渐变)
这里可以改
血条加减代码
cs
Sub Sheet2_按钮2_Click()
liliang = liliang + 1
Range("B1").Value = liliang
End Sub
Sub 按钮3_Click()
liliang = liliang - 1
Range("B1").Value = liliang
End Sub