Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-03-2015, 01:20 PM
semple.13 semple.13 is offline Need to find/replace text in many word files - but text is in embedded word files Windows 7 64bit Need to find/replace text in many word files - but text is in embedded word files Office 2013
Novice
Need to find/replace text in many word files - but text is in embedded word files
 
Join Date: Nov 2015
Posts: 3
semple.13 is on a distinguished road
Default I cobbled together a solution


Thanks for your help everyone; I ended up getting it figured out on my own. I probably should have mentioned that find and replace does not reach embedded documents without first opening them, and that many of the embedded files contain only pictures so changing them to straight text may not have been a good idea.

Likely not the best way to do it, but it works for my purposes:

Code:
Sub Test()
    Dim numObjects As Integer
    Dim oDoc As Document
    Dim strFilename As String
 
    Const strPath As String = "C:\Test Folder\"   'Our folder to look at
    'This makes a directory of files you want to look at (in the folder above, with the file extension specified)
    strFilename = Dir$(strPath & "*.doc*")
 
    'Loops through and checks every applicable file in the folder
    While Len(strFilename) <> 0
        Set oDoc = Documents.Open(strPath & strFilename)    'Makes a Document object for the current file
        oDoc.ActiveWindow.Visible = False
        numObjects = oDoc.InlineShapes.Count                'Count the number of InlineShapes (e.g. OLEs)
 
 
        If numObjects > 0 Then   'If there are any shapes (e.g. embedded objects), interact with them
            For Num = 1 To numObjects   'Iterate through each inline shape via index numbers
                If oDoc.InlineShapes(Num).Type = 1 Then   'If it's an embedded object (InlineShapes().Type = 1 indicates an OLE)
                    oDoc.InlineShapes(Num).OLEFormat.Open   'Open up the embedded object
                    ActiveDocument.ActiveWindow.Visible = False
                    Call FAR    'Find And Replace subroutine
                    ActiveDocument.Close    'Close the embedded object and continue to the next.  Not sure how _
                                            '_ to reference it besides "ActiveDocument" tbh.
                End If
            Next Num
        End If
        Debug.Print oDoc.FullName   'Error handling.
 
        'Closes the Document object and saves changes
        oDoc.Close wdSaveChanges
        'Clears it for the next iteration of the loop
        Set oDoc = Nothing
        strFilename = Dir$()
    Wend
End Sub
 
 
Sub FAR() 'Find And Replace
    ActiveDocument.ActiveWindow.Visible = False
    With Selection.Find 'Throughout the selection (the whole document)..
        .Text = "beep"
        .Replacement.Text = "boop"
        .Wrap = wdFindContinue
        .Execute Replace:=wdReplaceAll
    End With
End Sub
Reply With Quote
Reply

Tags
embedded word document, macro find and replace



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need to find/replace text in many word files - but text is in embedded word files Find & replace footer text in a folder of Word 2010 documents kennethc Word 3 03-28-2015 02:49 AM
Word VBA Find Table Text Shading Colour and replace with another QA_Compliance_Advisor Word VBA 10 09-19-2014 08:36 AM
Need to find/replace text in many word files - but text is in embedded word files Word VBA Macro to Find and Replace based on the Alt Text of an Image bennymc Word VBA 1 01-27-2014 04:23 PM
Bulk Text alignment for multiple word files jbradf Word 0 08-29-2013 06:41 PM
Need to find/replace text in many word files - but text is in embedded word files Merging two Word files with one file having a text box Timothy2001 Word 3 01-23-2011 07:01 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:03 PM.


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