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. ubuntu安装微软雅黑和Consolas字体

    原文:http://fooler5.iteye.com/blog/2406227 [字体下载] YaHeiConsolas.tar:http://www.mycode.net.cn/wp-conten ...

  2. Win10子系统Ubuntu安装llvm+clang

    https://apt.llvm.org/ 首先 然后 再然后修改/etc/apt/sources.list,添加下面的东西 然后 参考: https://blog.kowalczyk.info/ar ...

  3. SpringBoot 使用okhttp3

    1.添加pom.xml依赖 <dependency> <groupId>com.squareup.okhttp3</groupId> <artifactId& ...

  4. 【系列教程1】Gradle入门系列一:简介

    Gradle是一种构建工具,它抛弃了基于XML的构建脚本,取而代之的是采用一种基于Groovy的内部领域特定语言.近期,Gradle获得了极大的关注. 这篇文章是Gradle教程的第一篇,我们有两个目 ...

  5. 小文笔记 - phantomjs

    小文笔记 - phantomjs 视频推荐: http://www.intalesson.com/compedium/phantom 2017-05-13 第一节:安装 Windows安装: 下载解压 ...

  6. 1、Keepalived及VRRP原理介绍

    keepalived:即在linux中vrrp协议的实现 http://www.keepalived.org/ 什么是Keepalived?  Keepalived是一个用C语言编写的路由软件.该项目 ...

  7. git切换分支报错:error: pathspec 'origin/XXX' did not match any file(s) known to git

    项目上有一个分支test,使用git branch -a看不到该远程分支,直接使用命令git checkout test报错如下: error: pathspec 'origin/test' did ...

  8. 突变注释工具SnpEff,Annovar,VEP,oncotator比较分析--转载

    https://www.jianshu.com/p/6284f57664b9 目前对于variant进行注释的软件主要有4个: Annovar, SnpEff, VEP(variant Effect ...

  9. 项目Alpha冲刺--5/10

    项目Alpha冲刺--5/10 1.团队信息 团队名称:基于云的胜利冲锋队 成员信息 队员学号 队员姓名 个人博客地址 备注 221500201 孙文慈 https://www.cnblogs.com ...

  10. uni-app去掉h5端的导航栏

    找到项目的根目录下的pages.json文件,添加一下内容,可以去掉对应页面的导航栏 附上代码 "app-plus":{ "titleNView": false ...