在学习Verilog中需要用带下标符号来表示建立时间和保持时间等参数。excel中输入比较麻烦,需要选中字符后,再选择字体中的下标选项。所以做了这个VBA来实现下标转换功能。
Sub sub_script()
Dim str_len
Dim str_num
Dim str_sta
str_num = Application.InputBox("From end of the string,enter the number of character to be processed", "Sub script", 2, Type:=1) '使用inputbox输入希望处理的字符,从字符串末尾开始从右到左计算个数
str_len = ActiveCell.Characters.Count '字符宽度
str_sta = str_len - str_num + 1 '将处理的第一个字符的位置
For str_sub = str_sta To str_len '从设定处理的第一个字符开始,逐个处理字符
With ActiveCell.Characters(str_sub, 1).Font '单独处理字串中的指定字符
.Superscript = False '字符作为上标
.Subscript = True '字符作为下标
End With
Next
End Sub
Sub super_script()
Dim str_len
Dim str_num
Dim str_sta
str_num = Application.InputBox("From end of the string,enter the number of character to be processed", "Sub script", 2, Type:=1)
str_len = ActiveCell