|
|
Thread Tools | Display Modes |
#1
|
||||
|
||||
VBA Word - Search Within Files Containing A String - Copy Files to New Folder
Hello to all,
I am trying to work out how to Copy some word files. I would like to search within files that contains the String or word [EDIT] in a directory. ** The directory may have subfolders If the file contains the string then - Copy the file to a new folder. I found some code that I have been trying to adapt . 'http://www.vbaexpress.com/forum/archive/index.php/t-48591.html Code:
Sub FindStringCopyFile() ' Find the String [EDIT] - within Word file ' Copy File to new folder Dim files DocFile Dim cDoc As Word.Document nDoc As Word.Document Dim cDocFN As String SourceFolder As String Dim DestinationPath As String FileFolder As String Dim nRng As Word.Range cRng As Word.Range Set nDoc = Documents.Add SourceFolder = GetFolder & "\" files = Dir(SourceFolder & "*.docx") Do While files <> "" Documents.Open SourceFolder & files Set nRng = nDoc.Content cDocFN = CStr(DocFile) Documents.Open cDocFN ' If Document contains String [EDIT] Set cRng = ActiveDocument.Content If InStr(1, oPara.Range.Text, "[EDIT]") = 1 Then FileFolder.Copy DestinationPath End If Next FileFolder ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges files = Dir() Loop End Sub Function GetFolder() As String Dim oFolder As Object GetFolder = "" Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0) If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.path Set oFolder = Nothing End Function To Summarize: I am trying to achieve : Search through documents in a directory that contain the string [EDIT] - within the document. ** Also The directory may have sub folders - to search through COPY those files to a new folder. - been stuck for 2 days now - not making any progress so any help welcome. Thank you so much - for taking the time to help me again J |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Way to search for a string in text file, pull out everything until another string? | omahadivision | Excel Programming | 12 | 11-23-2013 12:10 PM |
Movable Word template with linked files and hidden folder | Elmobram22 | Word | 6 | 11-15-2013 02:11 PM |
How to copy linked Excel and Word files and retain links | ashleynpeters1 | Word | 1 | 05-30-2013 02:25 PM |
Opening Word /Excel reinstalls files, loses recent files | adj1 | Office | 3 | 05-10-2013 12:27 AM |
Word Macro - change date in footer for all files in a folder | patidallas22 | Word VBA | 2 | 03-09-2012 08:14 AM |