Convert VBScript to VBA - so code can be used in an access project.
Yesterday I had a problem whereby I need some vbscript code - to search text files in a given folder and sub foler for a text search string and if it exists in the txt files copy them to a certain directory. SirBounty - came up with a beautiful piece of code for me that did exactly what I need - the code is below. When clicked you are asked to enter the string to search for and then bobs your uncle it does exactly what it says on the tin. Now this morning the criteria has changed I need to convert the VBScript to VBA and put it into an access database - the script will run the exact same except rather than entering the text - you willl select from a combo box and click a button to complete.
What I have tried so far is fairly basic _ I have created the form added the combo box - entered the items i want to appear in it - created the button - and for the moment hard coded the search string in - (I was hoping to get it working this way first then add in the pass from combo functionality. But I am fastly running around in cirlces and seeing as coding is my weak area I think its time for help
Code
Dim objFSO: Set objFSO = CreateObject("Scripting.Fi
leSystemOb
ject")
strFolder= "C:\Source\"
strDestination= "C:\Destination\"
strToFind = InputBox("What string are you looking for?", "Search String")
ProcessFolder objFSO.GetFolder(strFolder
)
Set objFSO=Nothing
wscript.quit
Sub ProcessFolder(strSource)
ProcessFiles strSource
For Each fld In strSource.SubFolders
ProcessFolder fld
Next
End Sub
Sub ProcessFiles(strSrc)
On error resume next
If err.Number=0 Then
For Each file In strSrc.Files
arrData=Split(objFSO.OpenT
extFile(fi
le.Path).R
eadAll,vbN
ewLine)
For Each item in arrData
If InStr(lcase(item), lcase(strToFind)) > 0 Then objFSO.CopyFile file.path, strDestination
counter + 1
Next
Next
End If
End Sub
Start Free Trial