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. MongoDB的C#驱动报错Server instance 127.0.0.1:27017 is no longer connected的解决方案

    使用C#的MondoDB驱动,一直没问题.结果最近,MongoCursor的ToList方法,取列表,总是报错 Server instance 127.0.0.1:27017 is no longer ...

  2. CentOS7使用命令连接网络配置

    背景 在安装完CentOS7无桌面的情况下,无法使用桌面图标连接,如下图所示,这时我们需要在配置文件中配置网络连接信息. 步骤 查看ip地址:ifconfig PS:在未连接网络之前,我们是查看不到i ...

  3. CentOS7 安装git服务器

    在CentOS7系统中安装git服务器有两种方法,分别为yum安装和下载git安装包手动安装,这篇文章只有下载git安装包手动安装方法. 方法一:使用yum安装 暂无 方法二:下载git安装包手动安装 ...

  4. 分块读取Blob字段数据(Oracle)

    试过了MSSQL的分块读取Blob字段,又尝试在Oracle下完成,发现还是可行的. 首先建立一个存储过程: create or replace procedure PRO_GET_BLOB(     ...

  5. C#开发者工具网

    使用key值[123456]对[50cms]进行对称加密-在线DES对称加密/解密- 开发者工具网  http://tool.sufeinet.com/Encrypt/DesEncrypt.aspx? ...

  6. tp框架中 关于数据库mysql 的一些疑点知识

    mysql创建索引, 通常是在 创建表的 同时/时候, 就创建了 即使是在win下, 用命令行操作数据库 , 也要比 图形界面的鼠标操作快得多 索引的类型有: unique, fulltext索引, ...

  7. Markdown语法参考

    参考博客: https://www.jianshu.com/p/f3147a804368 https://www.jianshu.com/p/191d1e21f7ed https://www.jian ...

  8. Redis,Memcache比较

    简单比较: Redis不仅仅支持简单的k/v类型的数据,同时还提供list,set,hash等数据结构的存储.memcache只支持简单的K/V类型数据, 不过memcache可以缓存其他东西如图片, ...

  9. 【NOIP 2016】Day2 T3 愤怒的小鸟

    Problem Description \(Kiana\) 最近沉迷于一款神奇的游戏无法自拔. 简单来说,这款游戏是在一个平面上进行的. 有一架弹弓位于 \((0,0)\) 处,每次 \(Kiana\ ...

  10. 【译】第45节---EF6-索引属性

    原文:http://www.entityframeworktutorial.net/entityframework6/index-attribute-in-code-first.aspx Entity ...