|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 413191246se 于 2022-11-30 23:37 编辑
* 图片(InlineShapes):不包含文字,全部删除(如果包含文字,将变得复杂了,要 OCR 识别,此处不谈)。
* 图形(包含文本框)(Shapes):有的不含文字,有的含有文字,根据 .HasText 属性提取后默认粘贴到文首,我将其剪切到文尾,放在六个星号“*”后面。
* 图文框(Frames):可能由文本框转换而来,也可能由表格(文字环绕)转换而来。删除后会自动提取文字到所在段落的前面或后面。
* 不知各位朋友们有何高见?请探讨及赐教,谢谢大家!
* 请试用最新更新的代码《删除图形》宏:(示例文档请自行建立)
- Sub a1130_DeleteShapes()
- '删除图形
- '红色文字提取自图文框/六个星号"*"后面文字提取自文本框/表格环绕将变成图文框
- Dim r As Range, t As Table, iShape As InlineShape, Frm As Frame, n&, m&
- With ActiveDocument
- If .Shapes.Count <> 0 Then .Content.InsertParagraphBefore: m = 1
- Set r = .Paragraphs(1).Range
- '表格取消文字环绕
- For Each t In .Tables
- t.Range.Rows.WrapAroundText = False
- Next
- '删除图片(InlineShape)
- For Each iShape In .InlineShapes
- iShape.Delete
- Next
- '删除图形(Shape)/文本框
- For n = .Shapes.Count To 1 Step -1
- With .Shapes(n)
- If .TextFrame.HasText <> 0 Then r.InsertBefore Text:=.TextFrame.TextRange.Text
- .Delete
- End With
- Next
- '删除图文框(Frame)
- For Each Frm In .Frames
- With Frm
- .Select
- .Delete
- Selection.ClearFormatting
- Selection.Font.Color = wdColorRed
- End With
- Next
- If m = 1 Then .Content.InsertAfter Text:=vbCr & "******" & vbCr & r.Text: r.Delete
- End With
- Selection.HomeKey 6
- DocInfo
- End Sub
- Sub DocInfo()
- With ActiveDocument
- MsgBox "页数/Pages = " & .ComputeStatistics(wdStatisticPages) & vbCr & _
- "字数/Characters = " & .ComputeStatistics(wdStatisticCharacters) & vbCr & vbCr & _
- "分节/Sections = " & .Sections.Count & vbCr & _
- "表格/Tables = " & .Tables.Count & vbCr & vbCr & _
- "图片/InlineShapes = " & .InlineShapes.Count & vbCr & _
- "图形/文本框/Shapes = " & .Shapes.Count & vbCr & _
- "图文框/Frames = " & .Frames.Count, 0 + 48, "文档信息"
- End With
- End Sub
复制代码
|
|