|
以下为代码:
- Sub Testdelpics()
- Dim MyName, Dic, Did, i, MyFileName
- 'On Error Resume Next
-
- lj = "F:\work\京韩四季拍卖\test"
-
-
- Set objFolder = Nothing
- Set objShell = Nothing
-
- t = Time
- Set Dic = CreateObject("Scripting.Dictionary") '创建一个字典对象
- Set Did = CreateObject("Scripting.Dictionary")
- Dic.Add (lj), ""
- i = 0
- Do While i < Dic.Count
- ke = Dic.Keys '开始遍历字典
- MyName = Dir(ke(i), vbDirectory) '查找目录
- Do While MyName <> ""
- If MyName <> "." And MyName <> ".." Then
- If (GetAttr(ke(i) & MyName) And vbDirectory) = vbDirectory Then '如果是次级目录
- Dic.Add (ke(i) & MyName & ""), "" '就往字典中添加这个次级目录名作为一个条目
- End If
- End If
- MyName = Dir '继续遍历寻找
- Loop
- i = i + 1
- Loop
-
- For Each ke In Dic.Keys
- MyFileName = Dir(ke & "*.doc*")
- Do While MyFileName <> ""
- Did.Add (ke & MyFileName), ""
- MyFileName = Dir
- Loop
- Next
-
- Dim App, WrdDoc As Document
- Set App = CreateObject("Word.Application")
-
- '打开这个Word文件!
-
- For Each ke In Did.Keys
-
- 'Debug.Print (Ke)
-
- On Error Resume Next
- If Len(Documents(ke).Name) > 0 Then
- 'Debug.Print (ke)
- 'Debug.Print (Err.Number)
- If Err.Number <> 0 Then
- Set WrdDoc = App.Documents.Open(ke)
- Else:
- Set WrdDoc = Documents(ke)
- End If
- End If
- 'Debug.Print (WrdDoc.Name)
- Call delPics(WrdDoc)
-
- Next
- End Sub
- Function delPics(curdoc As Document)
-
- Debug.Print (curdoc.Name)
- 'Debug.Print ("delPics")
- '
- Dim nGrap As InlineShape
- Dim nShap As Shape
-
- For Each nGrap In curdoc.InlineShapes '删除图片
- nGrap.Select
- nGrap.Delete
- Next
-
- For Each nShap In curdoc.Shapes '删除绘图
-
- nShap.Delete
- Next
- curdoc.Close (True)
- End Function
复制代码 浮于上方的图片好象删除不了,有时候又是浮于文字下方的图片删除不了,我该怎样修改呢?
|
|