查找Word文件中未格式化wdWrapInline的所有表格/图形

问题描述 投票:0回答:2

我的文件很少(1000+页),偶尔会发现表格或形状未格式化为“内联文本”... 我试图找到一个 VBA,它可以帮助我识别文档中未格式化为 wdWrapInline 的每个表格或内联形状。 我的文档有两种页面方向(纵向和横向)。

我试过简单的

For sec To doc.Sections.count
     Selection.Find.WrapFormat = wdWrapInline 

但这不正确。

提前致谢。

我尝试了简单的

Selection.Find.WrapFormat = 7
,但这不正确。

vba ms-word format shapes inline
2个回答
0
投票

这是你想要的吗?

Sub Find_all_table_figure_in_Word_file_not_formatted_wdWrapInline()

    'CheckWrapType()
    Dim shp As Shape ' Tables always in line so they don't have WrapFormat property.
    Dim sr As Range
    Dim d As Document
    Dim bk As Bookmark, i As Long 'you can bookmark them to navigate after
    Dim cln As New VBA.Collection ' or  you can store them in a collection object for further
    Dim ur As UndoRecord
    
    Set ur = Word.Application.UndoRecord
    Set d = ActiveDocument
    ur.StartCustomRecord "Find_all_table_figure_in_Word_file_not_formatted_wdWrapInline"
    
    Rem if you want to find all of they
    For Each sr In d.StoryRanges
        Rem if you just want all shapes in the main content of a doc only
        'If sr.StoryType = wdMainTextStory Then
        For Each shp In sr.ShapeRange
            If shp.WrapFormat.Type = wdWrapInline Then
                'Debug.Print shp.Name & " is inline."
            Else
                'Debug.Print shp.Name & " is not inline."
                Rem If you want to convert they into in line.
                'shp.ConvertToInlineShape
                i = i + 1
                d.Bookmarks.Add "shape" + VBA.CStr(i), shp.Anchor
                cln.Add shp
            End If
        Next shp
        'end if
    Next sr

    ur.EndCustomRecord
End Sub

0
投票

我正在寻找一个宏,它将找到所有设置为换行的表格,并将它们更改为内联。我对 VBA 的了解还不够,无法尝试此操作。你能帮忙吗?

© www.soinside.com 2019 - 2024. All rights reserved.