|
我的电脑WIN10 office2016
EXCEL 设置了 宏程序 读取 WORD 信息和对应的页数。
目前运行后,页数信息出来了,但是物料信息没有获取。
请大神指引。 附件有对应的内容
Sub 读取word()
'禁止系统刷屏,触发其他事件等
On Error Resume Next '// 发生错误,自动执行下一句,就是忽略错误
Application.ScreenUpdating = False '//关闭屏幕刷新
Application.DisplayAlerts = False '//关闭系统提示
Dim time_Start
time_Start = Timer '//开始时间
Dim strFolder As String
With Application.FileDialog(msoFileDialogFilePicker)
.Title = "Select File"
.InitialFileName = "d:\Users\Desktop\output\" '//存放地址
If .Show Then
strFolder = .SelectedItems(1)
End If
End With
Dim i, ture, od, j, z, zz, mytable, x, k, c, mid, Format
i = 1
Dim ow As Object
Set ow = GetObject("word.application")
If ow Is Nothing Then
Set ow = CreateObject("word.application")
ow.Visible = ture
End If
Set od = ow.Documents.Open(Filename:=strFolder)
Set ow = Nothing
j = 1
z = 0
zz = 0
x = od.Tables.Count
For k = 1 To od.Tables.Count
Set mytable = od.Tables(k)
For Each c In mytable.Range.Cells
If InStr(c, "物料:42") > 0 Then
If InStr(c, "4203") > 0 Then
Cells(i, 1) = mid(c, InStr(c, "4203"), 10)
Else
If InStr(c, "4202") > 0 Then
Cells(i, 1) = mid(c, InStr(c, "4202"), 10)
Else
If InStr(c, "4212") > 0 Then
Cells(i, 1) = mid(c, InStr(c, "4212"), 10)
Else
If InStr(c, "4210") > 0 Then
Cells(i, 1) = mid(c, InStr(c, "4210"), 10)
Else
If InStr(c, "4207") > 0 Then
Cells(i, 1) = mid(c, InStr(c, "4207"), 10)
End If
End If
End If
End If
End If
z = 1
Exit For
End If
Next
If z = 0 Then '判断是否发现新料码
j = j + 1
Else '发现新料码
'避免新料码上一页无表格
If (k - 1 <> 0) And (j > 1) Then
Set mytable = od.Tables(k - 1)
For Each c In mytable.Range.Cells
If InStr(c, "入库班组:") > 0 Then
zz = 1
End If
Next
If zz = 0 Then
j = j + 1
zz = 0
End If
End If
i = i + 1
If i - 2 <> 0 Then
Cells(i - 2, 2) = j
j = 1
End If
z = 0
End If
Next
Cells(i - 1, 2) = j
od.Close False
Application.ScreenUpdating = True '//恢复屏幕刷新
Application.DisplayAlerts = True '//恢复系统提示
MsgBox "本次检索共用时:" & Format(Timer - time_Start, "#0.0000") & " 秒", , "新能源工程部提示" '//提示所用时间
End Sub
|
|