Dim dFilePath As Object, OneKey
Sub main_proc()
Dim Wb As Workbook, Sht As Worksheet, Rng As Range
Set Wb = Application.ThisWorkbook
Set Sht = Wb.Worksheets(1) Set dFilePath = CreateObject("Scripting.Dictionary")
RecursionFolder ThisWorkbook.Path & "\" For Each OneKey In dFilePath.keys
Ar = dFilePath(OneKey)
Ar(2) = WordCount(Ar(1))
Debug.Print Ar(2) & " " & Ar(1)
dFilePath(OneKey) = Ar
Next OneKey With Sht
.UsedRange.Offset(1).Clear
Set Rng = .Range("A2")
Set Rng = Rng.Resize(dFilePath.Count, 3)
Rng.Value = Application.Rept(dFilePath.items, 1)
End With Set Wb = Nothing
Set Sht = Nothing
Set Rng = Nothing
Set dFilePath = Nothing
End Sub
Sub RecursionFolder(ByVal FolderPath As String)
Dim Fso As Object
Dim MainFolder As Object
Dim OneFolder As Object
Dim OneFile As Object
Set Fso = CreateObject("Scripting.FileSystemObject")
Set MainFolder = Fso.GetFolder(FolderPath)
For Each OneFile In MainFolder.Files
If OneFile.Name Like "*.doc*" Then
dFilePath(dFilePath.Count + 1) = Array(OneFile.Name, OneFile.Path, 0)
End If
Next
For Each OneFolder In MainFolder.SubFolders
RecursionFolder OneFolder.Path
Next
Set Fso = Nothing
Set MainFolder = Nothing
End Sub Private Function WordCount(ByVal FilePath As String) As Long
Dim wdApp As Object
Dim wdDoc As Object On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If wdApp Is Nothing Then
Set wdApp = CreateObject("Word.Application")
End If
On Error GoTo 0 WordCount = 0
On Error Resume Next
Set wdDoc = wdApp.Documents.Open(FilePath)
If wdDoc Is Nothing Then
wdApp.Quit
Set wdApp = Nothing
On Error GoTo 0
Exit Function
Else
WordCount = wdDoc.ComputeStatistics(0, False) '0为字数
wdDoc.Close False
wdApp.Quit
Set wdApp = Nothing
End If
End Function

  

20171023xlVBA递归统计WORD字数的更多相关文章

  1. 使用JQ实现统计剩余字数

    JQ实现统计文本框剩余字数 效果图: 代码如下,复制即可使用: <html lang="en"> <head> <meta charset=" ...

  2. PHP 中如何正确统计中文字数

    PHP 中如何正确统计中文字数?这个是困扰我很久的问题,PHP 中有很多函数可以计算字符串的长度,比如下面的例子,分别使用了 strlen,mb_strlen,mb_strwidth 这个三个函数去测 ...

  3. LaTeX统计文章字数

    今天学会了用LaTeX命令统计文章字数,命令如下: textcount doc_full_path.tex 效果如下:

  4. word统计章节字数

    只有我这么无聊了..写论文的时候发现每次想看这个章节的字数统计时,还需要全选然后再看字数统计,太麻烦了.所以想着用宏写个能直接查看选定章节的字数统计. 具体方法如下: 建立宏:视图--宏--录制宏-- ...

  5. Delphi 统计Word文档中的字数

    急待解决的问题就是如何用delphi实现word中的统计字数 另外想多了解一些关于操作word的相关内容 比如用ole动态创建的和TWordApplication的偏重点在哪里,有什么不同等等…… 用 ...

  6. 统计 Word 文档字数的方式

    描述 欲统计某文档的字数,有两种方式. "审阅"选项卡--"校对"组--字符统计 点击左下角字数统计 审阅查看字数 此步骤较为复杂,在审阅选项卡中可以查询文档的 ...

  7. 【原创】大数据基础之词频统计Word Count

    对文件进行词频统计,是一个大数据领域的hello word级别的应用,来看下实现有多简单: 1 Linux单机处理 egrep -o "\b[[:alpha:]]+\b" test ...

  8. java统计中英文字数 Java问题通用解决代码

    http://yangchao20020.blog.163.com/blog/static/483822472011111635424751/   这个不适用于新浪微博字数的统计,结果有差别,若需要可 ...

  9. AJPFX:实现递归统计文件夹的总大小

    class Statistical {    public static void main(String[] args) {        Scanner sc = new Scanner(Syst ...

随机推荐

  1. rsync: read error: Connection reset by peer (104)

    Centos7    rsync守护进程上传文件失败 [root@nfs ~]# rsync -avz /etc rsync_backup@172.16.1.41::backupsending inc ...

  2. noip模拟【tea】

    tea [题目描述]有n个容量为V的瓶子,第i个瓶子中装着a[i]个单位的tea,使所有瓶子内的tea在不 超过其容量的前提下,非空的瓶子最少.在一个单位时间内,可以同时将多个瓶子中的tea倒入另外多 ...

  3. Git rebase使用

    目录 rebase的优点和缺点 分支内合并多个commit为一个新commit使用: 命令: 使用: 将其他分支合并到主分支,表现为线性: 将其他分支多个commit合并到主分支,并形成一个新comm ...

  4. FileAttributes Enum

    https://docs.microsoft.com/en-us/dotnet/api/system.io.fileattributes?view=netframework-4.7.2 读取FileA ...

  5. IE8下面parseInt('08')、parseInt('09')会转成0

    例子: <html> <body> <script type="text/javascript"> for(var i=1;i<=20;i ...

  6. 论文阅读:Prominent Object Detection and Recognition: A Saliency-based Pipeline

    论文阅读:Prominent Object Detection and Recognition: A Saliency-based Pipeline  如上图所示,本文旨在解决一个问题:给定一张图像, ...

  7. [LightOJ 1370] Bi-shoe and Phi-shoe(欧拉函数快速筛法)

    题目链接: https://vjudge.net/problem/LightOJ-1370 题目描述: 给出一些数字,对于每个数字找到一个欧拉函数值大于等于这个数的数,求找到的所有数的最小和. 知识点 ...

  8. GPIO实验之c语言

    上一章节进行实验使用的是汇编进行编程的,本次实验是使用c语言进行编写的. (1)点亮一个led灯   1)启动文件:    crt.S   .text   .global _start   _star ...

  9. powerdesigner反转数据库的设计图

    PowerDesigner导入sql文件 1:点击 2:弹出该页面,点击确定 3:弹出一下页面,点击下面按钮选择文件 4:点击确定完成 二 .表转换为中文的执行脚本及步骤 执行脚本为:Option E ...

  10. HDU 4312 Meeting point-2(切比雪夫距离转曼哈顿距离)

    http://acm.hdu.edu.cn/showproblem.php?pid=4312 题意:在上一题的基础上,由四个方向改为了八个方向. 思路: 引用自http://blog.csdn.net ...