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. topcoder srm 692 div1 -23

    1.给定一个带权有向图.选出一些边满足使得任意两点可相互到达的前提下使得选出的边的权值的最大最小差值最小. 思路:二分答案,然后枚举权值的范围判断是否可行. #include <stdio.h& ...

  2. MSYS2 更换国内源

    转自 : http://www.cnblogs.com/findumars/p/6546088.html 最近一段时间不知怎么的,使用默认的 MSYS2 源升级软件或是安装新软件的特别的慢.所以就翻了 ...

  3. 三星sm865

    目录 样张 SSD-Z: CrystalDiskInfo: CrystalDiskMark: AS-SSD Benchmark: 颗粒检查: 扇区信息: HD Tune Pro: 三星Magician ...

  4. MUSIC分辨率与克拉美罗下界的关系

    https://www.cnblogs.com/rubbninja/p/4512765.html

  5. HDU 3506 Monkey Party(区间DP)题解

    题意:有n个石堆排成环,每次能合并相邻的两堆石头变成新石堆,代价为新石堆石子数,问最少的总代价是多少 思路:先看没排成环之前怎么做:用dp[i][j]表示合并i到j所需的最小代价,那么dp[i][j] ...

  6. Eclipse 创建maven项目 报错 one or more constraints have not been satisfied

    首先 在 pom.xml > plugins 中添加 <plugin> <groupId>org.apache.maven.plugins</groupId> ...

  7. (zhuan) Building Convolutional Neural Networks with Tensorflow

    Ahmet Taspinar Home About Contact Building Convolutional Neural Networks with Tensorflow Posted on a ...

  8. 【C#】可空类型 NullAble<T>

    在实际编写代码时候 ,  会遇到很多场景, 需要将值置成空, 比如发货日期, 有可能是没有. 在没有可空类型之前, 程序都是用 魔值, 即为一个minValue或者常量, 来代表这个值为空, 也有用一 ...

  9. 微服务架构与实践4_Docker

    构建Docker映像 定义Dockerfile=>Docker根据Dockerfile构建出映像 包含: 基础映像(父映像)信息 维护者信息 映像操作命令 容器启动命令 .net standar ...

  10. 6、nginx的反向代理及缓存功能

    nginx模块的应用 ngx_http_proxy_module  nginx 反向代理模块: http://nginx.org/en/docs/http/ngx_http_proxy_module. ...