View Single Post
 
Old 05-11-2020, 09:23 AM
gmaxey gmaxey is offline Windows 10 Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Paul (Macropod) already knows this and can likely improve on this code. While his posted solution solved the OP's issue, for completeness the code provided will not remove all images/graphics/shapes/lines or whatever we want to call them from a document.


While the find string posted will find all inline graphics in the document if run from the user interface, it will only find the inline graphics in the currently selected storyrange if run via VBA. Also the find string posted regardless of how run will not find any floating graphics/shapes.

Code:
Public Sub RelaceAllGraphicsWithNothing()
Dim rngStory As Word.Range
Dim lngJunk As Long
Dim lngIndex As Long
  'Fix the skipped blank Header/Footer problem
  lngJunk = ActiveDocument.Sections(1).Headers(1).Range.StoryType
  'Iterate through all story types in the current document
  For Each rngStory In ActiveDocument.StoryRanges
    'Iterate through all linked stories
    Do
      SrcAndRplInStory rngStory, "^g^p", ""
      SrcAndRplInStory rngStory, "^g^l", ""
      SrcAndRplInStory rngStory, "^g", ""
      For lngIndex = rngStory.ShapeRange.Count To 1 Step -1
        rngStory.ShapeRange.Item(lngIndex).Delete
      Next lngIndex
      'Get next linked story (if any)
      Set rngStory = rngStory.NextStoryRange
    Loop Until rngStory Is Nothing
  Next
lbl_Exit:
  Exit Sub
End Sub
Public Sub SrcAndRplInStory(ByVal rngStory As Word.Range, _
                                  ByVal strSearch As String, _
                                  ByVal strReplace As String)
  With rngStory.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = strSearch
    .Replacement.Text = strReplace
    .Execute Replace:=wdReplaceAll
  End With
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote