Excel VBA

来源:互联网 发布:淘宝李宁是真的吗 编辑:程序博客网 时间:2024/05/17 05:15

添加工作表

Sheets.Add

ActiveSheet.Name = "汇总"

或者

Worksheets.Add
ActiveSheet.Name = "汇总"

Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "target"


Sub Excute_Click()
'原始注音音节数量
Dim orign_zy_syllable_coun
orign_zy_syllable_count = Cells(Rows.Count, 1).End(3).Row
'原始注音音节
Dim orign_zy_syllable As String
Dim new_zy_syllable As String
'新建工作表
Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = Worksheets.Count + 1
For i = 2 To orign_zy_syllable_count
orign_zy_syllable = Worksheets("拼音音节VS注音音节").Cells(i, 3).Value


new_zy_syllable = orign_zy_syllable & "0"
Cells(5 * (i - 2) + 1, 1).Value = 5 * (i - 2) + 1
Cells(5 * (i - 2) + 1, 2).Value = new_zy_syllable
Cells(5 * (i - 2) + 1, 3).Value = Convert_Unicode_Str(orign_zy_syllable, 0, 5 * (i - 2) + 1)


new_zy_syllable = orign_zy_syllable & "1"
Cells(5 * (i - 2) + 2, 1).Value = 5 * (i - 2) + 2
Cells(5 * (i - 2) + 2, 2).Value = new_zy_syllable
Cells(5 * (i - 2) + 2, 3).Value = Convert_Unicode_Str(orign_zy_syllable, 1, 5 * (i - 2) + 2)


new_zy_syllable = orign_zy_syllable & "2"
Cells(5 * (i - 2) + 3, 1).Value = 5 * (i - 2) + 2
Cells(5 * (i - 2) + 3, 2).Value = new_zy_syllable
Cells(5 * (i - 2) + 3, 3).Value = Convert_Unicode_Str(orign_zy_syllable, 2, 5 * (i - 2) + 3)


new_zy_syllable = orign_zy_syllable & "3"
Cells(5 * (i - 2) + 4, 1).Value = 5 * (i - 2) + 3
Cells(5 * (i - 2) + 4, 2).Value = new_zy_syllable
Cells(5 * (i - 2) + 4, 3).Value = Convert_Unicode_Str(orign_zy_syllable, 3, 5 * (i - 2) + 4)


new_zy_syllable = orign_zy_syllable & "4"
Cells(5 * (i - 2) + 5, 1).Value = 5 * (i - 2) + 4
Cells(5 * (i - 2) + 5, 2).Value = new_zy_syllable
Cells(5 * (i - 2) + 5, 3).Value = Convert_Unicode_Str(orign_zy_syllable, 4, 5 * (i - 2) + 5)
Next


End Sub


Public Function Convert_Unicode_Str(str As String, tone As Integer, lineNo As Integer)
'取得十六进制的UNICODE
    Dim i As Long
    Dim chrTmp As String
    Dim ByteLower As String
    Dim ByteUpper As String
    Dim strReturn As String
    strReturn$ = strReturn$ & "{ " & lineNo & ", { "
    For i = 1 To Len(str)
        chrTmp$ = Mid(str, i, 1)
        ByteLower$ = Hex$(AscB(MidB$(chrTmp$, 1, 1)))
        If Len(ByteLower$) = 1 Then
            ByteLower$ = "0" & ByteLower$
        End If
        ByteUpper$ = Hex$(AscB(MidB$(chrTmp$, 2, 1)))
        If Len(ByteUpper$) = 1 Then
            ByteUpper$ = "0" & ByteUpper$
        End If
        strReturn$ = strReturn$ & "0x" & ByteUpper$ & ByteLower$ & ","
    Next
    If tone = 0 Then
        strReturn$ = strReturn$ & "0x02D9" & ","
    ElseIf tone = 1 Then
        strReturn$ = strReturn$ & "0" & ","
    ElseIf tone = 2 Then
        strReturn$ = strReturn$ & "0x02CA" & ","
    ElseIf tone = 3 Then
        strReturn$ = strReturn$ & "0x02C7" & ","
    Else
        strReturn$ = strReturn$ & "0x02CB" & ","
    End If
    
    For i = Len(str) + 2 To 7
        strReturn$ = strReturn$ & "0" & ","
    Next
    strReturn$ = strReturn$ & tone & "} },"
    Convert_Unicode_Str = strReturn$
End Function


0 0
原创粉丝点击