VBA统计WORD文档中汉字、英文及其组合出现的次数,并输出

使用前,需要在word内插入一个textbox1和一个commandbutton1,然后去掉文档中的标点符号。笔者比较懒,未加入剔除标点的代码。VBA统计WORD文档中汉字、英文及其组合出现的次数,并输出_第1张图片

理论上下述代码可以统计999个字符(含标点)的文本,如需增加文本数量,则只需要增加数组体积即可。
代码只是通过比较简单的for ,do循环实现,没啥技术含量哈。

Sub Button1_click()
    '统计词频
    Dim input_word As String
    Dim input_word_part(1 To 9999) As String
    Dim output_word_part(1 To 9999) As String
    Dim temp_input_word_part As String
    Dim count_word(1 To 9999) As Integer
    Dim count_output As String
    Dim input_len As Integer
    Dim i, j, k, p As Integer
    
'i为数组序号,'j为字符长度
'input_word_part()为全部元素
'output_word_part()为去重后元素


input_word = Trim(TextBox1.Text)
input_len = Len(input_word)

'数组赋值
i = 1
j = 1
Do While j <= 9
    If Len(Mid(input_word, i, j)) = j Then
        input_word_part(j * 1000 + i) = Mid(input_word

你可能感兴趣的:(VBA编程,数据提取,专利撰写,数据优化)