|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
VBScript (VBS) - Scripting with Microsoft Word Problem
I am new to scripting and I need some help please.
I have microsoft word files in folderA. I need to search all word files for a string, if it finds the string, I need it to move that one file to folderB and then move onto the next file. I will post the code I have so far. Please note, my word files end in .T00 or .T01 but its really a .doc or .rtf. I have adjusted my code to look for anything ending with .T** Any help is greatly appreciated. Thanks Kris '***********************************' Option Explicit Dim fso, StdOut, fFile, fFolder, sSource, sDest, tx, sText, nPosStart, nPosEnd, objFSO Dim wrdo, strReadDocName, strWriteDocName, TargetFolder1 Dim objShell1 Dim objFolder1 Dim colItems1 Dim objItem1 TargetFolder1 = "C:\DTS\Send\" Set objShell1 = CreateObject("Shell.Application") Set objFolder1 = objShell1.Namespace(TargetFolder1) Set colItems1 = objFolder1.Items For Each objItem1 In colItems1 If InStr(2, objItem1.Name, ".T") <> 0 Then Set wrdo = CreateObject("Word.Application") wrdo.Visible = FALSE wrdo.Documents.Open(targetfolder1 & objitem1.name) If wrdo.Documents.Application.Selection.Find.Text = "thestring" Then 'If wrdo.Documents.Application.Selection.Find.Text = "<....................>" Then 'If wrdo.Documents.Application.Selection.Find.Text = "|" & Chr(144) & "|" Then wrdo.ActiveDocument.Close wrdo.Application.Quit 'Set objFSO = CreateObject("Scripting.FileSystemObject") 'objFSO.MoveFile (targetfolder1 & objitem1.name), "C:\DTS\Send\WrongMarker\" Else wrdo.ActiveDocument.Close wrdo.Application.Quit End IF Set wrdo = Nothing Else End If Next |
|
#2
|
|||||
|
|||||
|
You haven't said what's not working, but I do see a few improper method calls. I've cleaned up your code a little bit and fixed the method calls. I've also removed some unnecessary conditional statements. See if this works any better for you. If not, please post your error message.
vb Code:
__________________
Scripting problems? Windows questions? Ask the Windows Guru! Stay up to date with all of my latest content. Follow me on Twitter! Help us help you! Post your exact error message with these easy tips! |
|
#3
|
||||
|
||||
|
I also want to add, since you're using the Shell.Application object to iterate through your files, there's no need to use the FileSystemObject to move them. You're just creating an extra object to do something that the Shell Automation object can do natively (with the MoveHere method). Use one or the other, not both.
I recommend going with the FileSystemObject all the way around since the code is easier to use. |
|
#4
|
|||
|
|||
|
Quote:
Thank you for your reply. I am not sure how to rewrite it in the file script like you suggested nor do I know the .movehere option. Is there a good place to go for word.application options that I can use? I am not getting an error message, it just isn't moving the file when it finds a simple word like "teacher". I can see it open the script in taskmanager and then open word for each file, it just isn't moving the files. Any ideas? Please help. |
|
#5
|
|||
|
|||
|
Is it possible that there is a problem with the following line?
If blnMove Then Set objFso = CreateObject("Scripting.FileSystemObject") objFso.MoveFile strTarget & objItem.Name, "C:\DTS\Send\WrongMarker\" End If Should it be something like ..... If blnMove = "True" Then Set objFso = CreateObject("Scripting.FileSystemObject") objFso.MoveFile strTarget & objItem.Name, "C:\DTS\Send\WrongMarker\" End If I have tried that but it didn't work. |
|
#6
|
||||||
|
||||||
|
Quote:
You can find information about the Word Automation object here. It sounds as though your text search isn't finding anything. Here's how I would do this. vb Code:
You might also read my articles: Scripting Microsoft Word Reading and Printing Word Documents in WSH Advanced Word Object Scripting |
|
#7
|
|||
|
|||
|
That did it. Thanks so much for the help. I will be sure to use those links.
Kris. ![]() |
|
#8
|
||||
|
||||
|
Quote:
|
![]() |
| Viewing: ASP Free Forums > System Administration > Windows Scripting > VBScript (VBS) - Scripting with Microsoft Word Problem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|