Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-02-2015, 01:51 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 Need to find/replace text in many word files - but text is in embedded word files


Hi all,

I'm having an issue where my predecessor made a ton of Word files, and instead of copying/pasting paragraphs like a sane person, he embedded Word documents into Word documents.

I now need to add a sentence to each and every one of these documents. I intended to use a find/replace macro to search each file in the folder, but I'm not sure how to modify it to search through each embedded Word object within each Word document.

Here's the VBA macro I had found and planned to use before realizing text was in embedded objects within the documents:
http://www.extendoffice.com/document...ple-files.html
Reply With Quote
  #2  
Old 11-02-2015, 03:58 PM
macropod's Avatar
macropod macropod 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 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

If the embedded content is linked to another file (as a reasonable person might do if the content needs to be kept in synch), all you need do is edit the source files.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 11-03-2015, 09:20 AM
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
Unhappy

Unfortunately, that isn't the case--this guy wasn't very computer savvy. To the best of my knowledge, this means I need to go through and open each file in the folder, open each embedded document in each file, and do a find/replace.
Reply With Quote
  #4  
Old 11-03-2015, 11:02 AM
Charles Kenyon Charles Kenyon is offline Need to find/replace text in many word files - but text is in embedded word files Windows 8 Need to find/replace text in many word files - but text is in embedded word files Office 2013
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,140
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

This may give you a start. I do not know that it will reach the embedded documents.
How to Find & ReplaceAll on a batch of documents in the same folder
Reply With Quote
  #5  
Old 11-03-2015, 11:05 AM
Charles Kenyon Charles Kenyon is offline Need to find/replace text in many word files - but text is in embedded word files Windows 8 Need to find/replace text in many word files - but text is in embedded word files Office 2013
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,140
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

While you are at it, you might try changing the embedded files to links or straight text.
Reply With Quote
  #6  
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:18 AM.


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