Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #8  
Old 05-11-2020, 09:23 AM
gmaxey gmaxey is offline Remove all the images in a document, including the new lines Windows 10 Remove all the images in a document, including the new lines Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,617
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
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
 

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Remove all the images in a document, including the new lines How do I Remove A Specific Amount of Characters from Lines in a Document? tatihulot Word 5 01-22-2016 05:55 AM
Remove all the images in a document, including the new lines How to Prevent Table of Contents Including Document Details shaaa Word 5 06-10-2015 03:52 PM
How to stop including images as attachment (in other e-mail clients)? TylerSD Outlook 0 12-05-2014 01:56 PM
hard lines across document - can't remove joanieS Word 3 07-30-2013 11:29 AM
Remove all images from a Mac OS X Word 2008 Document? qcom Drawing and Graphics 0 04-23-2011 06:48 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:08 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft