如何在此代码中导入可读性统计函数?

时间:2015-02-20 11:49:56

标签: excel vba excel-vba ms-word word-vba

我有一个代码,可以选择多个Word文件并打开它们,并在Excel文件中记录它们的路径。此代码链接到Excel表单中的命令按钮。代码如下:

 Dim DocStats As String
 Dim WordFileName As String


  Call Application.FileDialog(msoFileDialogOpen).Filters.Clear
 Call Application.FileDialog(msoFileDialogOpen).Filters.Add( _
 "Word Files Only", "*.docx")

 'allow the user to select multiple files
 Application.FileDialog(msoFileDialogOpen).AllowMultiSelect = True
 'make the file dialog visible to the user
 intChoice = Application.FileDialog(msoFileDialogOpen).Show
 'determine what choice the user made
 If intChoice <> 0 Then
'get the file path selected by the user
For i = 1 To Application.FileDialog(msoFileDialogOpen _
    ).SelectedItems.Count
    strPath = Application.FileDialog(msoFileDialogOpen _
    ).SelectedItems(i)
    j = Cells(Rows.Count, 1).End(xlUp).Row + 1
    'print the file path to sheet 1
    Cells(j, 1) = strPath

    Set WordApp = CreateObject("Word.Application")
    WordApp.Documents.Open strPath
    WordApp.Visible = True

    With WordApp.Documents.Content

    DocStats = WordApp.ReadabilityStatistics(strPath).Value
    MsgBox DocStats, vbOKOnly, "Hello"
    Cells(j, 2) = DocStats

    End With

Next i
End If

End Sub

现在我想将http://word.tips.net/T001784_Only_Showing_Readability_Statistics.html中的ReadabilityStatistics代码导入到此代码中,以便在记录路径时,还会记录word文件的可读性统计信息。请帮忙。

1 个答案:

答案 0 :(得分:0)

将您的With块替换为

With WordApp.ActiveDocument.Content

For j = 1 To .ReadabilityStatistics.Count
  DocStats = DocStats & .ReadabilityStatistics(j)
  DocStats = DocStats & ": "
  DocStats = DocStats & .ReadabilityStatistics(j).Value
  DocStats = DocStats & vbCrLf
Next j

MsgBox DocStats, vbOKOnly, "Hello"
Cells(j, 2) = DocStats

End With