1

I have few files (1000+ pages) and occasionally find table or shape not formatted "Inline with Text"... I tried to find a VBA that can help me identify every table or inline shape in my document that are not formatted wdWrapInline. My documents have both page orientations (portrait and landscape).

I tried simple

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

but that's not correct.

Thanks in advance.

I tried simple Selection.Find.WrapFormat = 7 but that's not correct.

Oscar Sun
  • 1,427
  • 2
  • 8
  • 13

1 Answers1

0

Is this what you want?

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
Oscar Sun
  • 1,427
  • 2
  • 8
  • 13
  • Thanks Oscar. It got me 90% there. 1) it checks header/footer as well, can we skip that as there is logo image in the header/footer... 2) can start on let's say 3rd section break instead of from the beginning... – user22139624 Jul 12 '23 at 14:58
  • @user22139624 Yes we can, however you have not mentioned any of these before. Shall I do it for you? Or do you want to try to adjust it yourself? Can you? Try to do it yourself and come back if you have any problems. If it doesn't work, I'll try again. Okay? If my answer solves your problem, can you please accept this answer to close your question, and [the previous one](https://stackoverflow.com/a/76594897/8249058) as well? Thank you very much. – Oscar Sun Jul 12 '23 at 15:50
  • 1
    I got the skip part working but not the header part yet. Will keep trying for a bit. – user22139624 Jul 12 '23 at 16:34
  • @user22139624 That's fine! come on! Good luck. Welcome to see you then come in to discuss any problems. – Oscar Sun Jul 12 '23 at 17:09
  • @user22139624 Congratulations you did it, are you? So it's all of yours, not mine, that's your effort to make it, my part is just a guide to show you the roads to arrive there. – Oscar Sun Jul 13 '23 at 00:39