|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
下面这段代码运行时当MyWord.Range(i, i + 1)中的i值达到一万一千多时提示错误代码“4608”,并显示“数值超出范围”,请大师指点,谢谢!
Sub 调试()
Dim AppWord As Object 'word程序对象
Dim MyWord As Object 'word文档对象
Dim mf
Dim MySheet As Worksheet '用于输出的工作表对象
Dim R_sc As Long '输出行
Dim fso As Object 'fso对象
Dim InputPath, Cha As String '提取数据的文件夹路径
Dim S_start As Long '选取字符的开始位置
Dim S_end As Long '选取字符的结尾位置
Set MySheet = ThisWorkbook.Sheets("调试")
MySheet.Range("A3:H200").Clear '清空输出表
InputPath = ThisWorkbook.Path
mf = Dir(ThisWorkbook.Path & "\*田径运动会*.doc*")
Set AppWord = CreateObject("Word.Application")
If mf <> "" Then
Set MyWord = AppWord.Documents.Open(ThisWorkbook.Path & "\" & mf)
AppWord.Visible = True
Else
MsgBox "没有这个Word文档!", 16, "警告......"
End If
'遍历word文档中的字符并赋值给变量Cha
j = 3
k = 0
For i = 0 To MyWord.Range.End
k = k + 1
Cha = MyWord.Range(i, i + 1)
MySheet.Cells(j, k) = Cha
MySheet.Cells(j + 1, k) = Asc(Cha)
If Cha Like "*[一-龥]*" Then
MySheet.Cells(j + 1, k) = "是" & i
Else
MySheet.Cells(j + 1, k) = "否" & i
End If
If (i + 1) Mod 20 = 0 Then
k = 0
j = j + 3
End If
Next
MyWord.Close
Set MyWord = Nothing
AppWord.Application.Quit
Set MySheet = Nothing
Set AppWord = Nothing
Set fso = Nothing
End Sub
|
|