Sub 查找相同字符个数()
Text = InputBox("请输入您要查找到字符:", "信息提示")
Dim result As String
For i = 1 To 45
Text = "[" + Trim(str(i)) + "]" '注意数值转成字符串会在前面加上空格,所以要用trim去除空格
Text = Trim(Text)
With ActiveDocument.Content.Find
Do While .Execute(FindText:=Text) = True
tim = tim + 1
Loop
End With
'输出到字符串
result = result + Text + "," + str(tim) + ";"
tim = 0
Next i
'将结果写入到文本文件
Call Write2Txt(result, "F:/24.txt")
End Sub
'fileAdress 如 C:/FSOTest/TestFile.txt
Function Write2Txt(str As String, fileAdress As String)
Dim sFile As Object, fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set sFile = fso.CreateTextFile(fileAdress, True)
sFile.WriteLine (str)
sFile.Close
Set sFile = Nothing
Set fso = Nothing
End Function
VBA查询word中的字符串
最新推荐文章于 2024-06-11 10:37:13 发布