看看如下代码是否可行 Sub test() '请将所有问卷文档保存于指定的文件夹(暂定为E:\ddd) Dim ndoc As String, odoc As Document Dim mytext As String, mycount As String, i As Integer, n As Integer ChDrive "E" '设置当前驱动器 ChDir "E:\ddd" '确定目录路径 ndoc = Dir("*.doc") Application.ScreenUpdating = False Do While ndoc <> "" '在指定目录内各文档循环操作 n = n + 1 Set odoc = Documents.Open(ndoc) With odoc.Content.Find '查找红色数字 .ClearFormatting .Font.Color = wdColorRed .Format = True .MatchWildcards = True '如果找到,则记录其题号及数字选项 Do While .Execute(findtext:="[1-3]", Forward:=True) = True With .Parent mytext = mytext & Replace(odoc.Name, "doc", "") _ & ":no" & .Cells(1).RowIndex - 1 & vbTab & .Text & vbCr .Move Unit:=wdRow, Count:=1 End With Loop End With odoc.Close False ndoc = Dir() Loop '分问题统计答卷情况 For i = 1 To 32 mycount = mycount & "No." & i & vbTab & UBound(Split(mytext, "no" & i & vbTab & "1")) & vbTab _ & UBound(Split(mytext, "no" & i & vbTab & "2")) & vbTab _ & UBound(Split(mytext, "no" & i & vbTab & "3")) & vbCr Next i '创建新文档并插入统计表格 Documents.Add Selection.InsertAfter "题号" & vbTab & "是" & vbTab & "否" & vbTab & "不确定" & vbCr & mycount Selection.ConvertToTable Separator:=vbTab, numcolumns:=4 With ActiveDocument.Tables(1) .Style = "网格型" .Borders.Enable = True .PreferredWidthType = wdPreferredWidthPercent .PreferredWidth = 75 .Rows.Alignment = wdAlignRowCenter End With Application.ScreenUpdating = True MsgBox "共统计了" & n & "个文档。", vbInformation End Sub
[此贴子已经被作者于2007-5-18 13:15:47编辑过] |