【发布时间】:2014-02-10 00:05:39
【问题描述】:
我正在尝试创建一个报告,该报告分析文件夹中的多个 word 文档并分析文档中的复选框以确定一组测试是通过还是失败。我有循环遍历文件夹中所有文档的代码,但我很难确定如何确定这些框是否被选中。
我要评估的第一个复选框被标记为“PassCheckBox”。我找到了几篇关于如何执行此操作的语法文章,但似乎没有一篇文章适用于我遍历 word 文件的方式。当我尝试运行时,我当前的代码给了我“需要对象”。
这是我当前的代码:
Sub ParseTestFiles()
Dim FSO As Object
Dim fPath As String
Dim myFolder, myFile
Dim wdApp As Object
Dim PassValue As Boolean
fPath = ActiveWorkbook.Path
Set FSO = CreateObject("Scripting.FileSystemObject")
Set myFolder = FSO.GetFolder(fPath).Files
For Each myFile In myFolder
If LCase(myFile) Like "*.doc" _
Or LCase(myFile) Like "*.docx" Or LCase(myFile) Like "*.docm" Then
On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then 'Word not yet running
Set wdApp = CreateObject("Word.Application")
End If
On Error GoTo 0
wdApp.Documents.Open CStr(myFile)
wdApp.Visible = True
' Here is where I'm having an issue
PassValue = ActiveDocument.FormFields("PassCheckBox").Checked
Set wdApp = Nothing
End If 'LCase
Next myFile
End Sub
【问题讨论】:
标签: excel vba checkbox ms-word