I'M FINISHED!!!!

Special thanks to Kholm for his help in this project with his UDF.

This will pull a pvf file (text file) from a shared drive and will go through the file looking for USERID: in a line. When it finds this it creates a text file called userid with the date and time in the file name. Once it's finished going through the main file it will then insert each one of the text files into a template file, save it as a word doc, move it to another shared folder and email the path of each document to the user, and their group. Pretty involved, I would've gotten it done quicker but the powers above me kept changing how they wanted it done...
[Big Grin]

code:
Break on
Cls


:SearchForPVF
$PVFFile = Dir("\\Server\revbox\*.pvf")
While $PVFFile <> "" AND @ERROR = 0
GoSub CopyPvf
$PVFFile = Dir("")
Loop
Cls
If $FileToProcess = "Y"
Goto FormatToWord
Else
$Timer = 3
While $Timer <> 0
At(0,0) "Sleeping for $Timer seconds.. "
Sleep 1
$Timer = $Timer - 1
Loop
EndIf
Goto SearchForPVF


:CopyPvf
Select
Case Instr($PVFFile,"P1545IN1") <> 0 $CopytoFolder = "Lofs" $DistList = "P1545IN1"
Case Instr($PVFFile,"P3507IN1") <> 0 $CopyToFolder = "MiscInfo" $DistList = "P3507IN1"
Case Instr($PVFFile,"PQD62IN1") <> 0 $CopyToFolder = "MiscInfo" $DistList = "PQD62IN1"
Case Instr($PVFFile,"PAISSIN1") <> 0 $CopyToFolder = "MiscInfo" $DistList = "PAISSIN1"
Case Instr($PVFFile,"P3507DNM") <> 0 $CopyToFolder = "MiscInfo" $DistList = "P3507DNM"
Case 1 $CopyToFolder = "MiscInfo" $DistList = "P3507IN1"
EndSelect
Cls
AT(0,0) "Moving $PVFFile to C:\Invoices "
Shell '%Comspec% /c Move "\\Server\Revbox\$PVFFile" "C:\Invoices\$PVFFile"'
If @Error = 0
AT(1,0) "Successfully moved.."
Else
AT(1,0) "Unable to move..."
EndIf


:BurstPvfFile
$WriteToLog = Redirectoutput("C:\Invoices\Logs\Processed.Log")
? "@Date @Time Processing Started for Cycles"
$WriteToLog = Redirectoutput("")
AT(3,0) "Processing file C:\Invoices\$PVFFile "
$LineCounter = 0
If Open(1,"C:\Invoices\$PVFFile") = 0
$WriteToLog = Redirectoutput("C:\Invoices\Logs\Processed.Log")
? "@Date @Time Started processing file $PVFFile"
$WriteToLog = Redirectoutput("")
$UseridFound = "N"
$LineOfText = ReadLine(1)
While @error = 0
$LineCounter = $LineCounter + 1
If Instr($LineofText,"USERID") <> 0
$UseridFound = "Y"
$Userid = Substr("$LineOfText",8,25)
$Userid = Trim($Userid)
$WrittentoUserid = 0
$Hour = Substr(@Time,1,2)
$Min = Substr(@Time,4,2)
$Sec = Substr(@Time,7,2)
$FileName = "$Userid@MonthNo@MDayNo@Year$Hour$Min$Sec.txt"
$EmailIniFile = WriteProfileString("C:\Invoices\Email\SendMailTo.ini","$FileName","Userid","$Userid")
$EmailIniFile = WriteProfileString("C:\Invoices\Email\SendMailTo.ini","$FileName","DistList","$DistList")
$EmailIniFile = WriteProfileString("C:\Invoices\Email\SendMailTo.ini","$FileName","Cycle","$PVFFile")
$WriteToLog = Redirectoutput("C:\Invoices\Logs\Processed.Log")
? "@Date @Time Found userid $Userid, created $FileName"
$WriteToLog = Redirectoutput("")
EndIf
If $UseridFound = "Y"
$FileToProcess = "Y"
AT(6,0) "Writing to C:\Invoices\$CopyToFolder\$FileName "
$WritePDF = Redirectoutput("C:\Invoices\$CopyToFolder\$FileName")
"$LineOfText@CRLF"
$WritePDF = Redirectoutput("")
$WrittentoUserid = $WrittentoUserid + 1
AT(7,0) "Lines written to C:\Invoices\$CopyToFolder\$FileName $WrittentoUserid "
EndIf
AT(4,0) "Processed $LineCounter Lines "
$LineOfText = Readline(1)
Loop
$CloseFile = Close(1)
$Log = Redirectoutput("C:\Invoices\Logs\Processed.log")
? "@Date @Time Finished processing file $PVFFile"
$Log = Redirectoutput("")
AT(9,0) "Moving C:\Invoices\$PVFFile to \\Server1\Share1\Revbox"
Shell '%Comspec% /c Move "C:\Invoices\$PVFFile" "C:\Invoices\ProcessedPvf"1>Nul 2>Nul'
If @Error = 0
AT(10,0) "Moved Successfully..."
Shell '%Comspec% /c Del "E:\Revbox\$PVFFile" 1>Nul 2>Nul'
Else
AT(10,0) "Unable to move..."
EndIf
Sleep 2
EndIf
Return

:FormatToWord
$X = 1
While $X < 3
If $X = 1
$Directory = "Lofs" $Template = "C:\Invoices\Templates\Lofs.dot"
Else
$Directory = "Miscinfo" $Template = "C:\Invoices\Templates\MiscInfo.dot"
EndIf
Cls
AT(0,0) "Querying C:\Invoices\$Directory for files to format..."
$FileToFormat = Dir("C:\Invoices\$Directory\*.txt")
While $FileToFormat <> "" AND @ERROR = 0
$PathandFileToFormat = "C:\Invoices\$Directory\$FileToFormat"
$WriteToLog = Redirectoutput("C:\Invoices\Logs\Processed.Log")
? "@Date @Time Formatting file $FileToFormat to word."
$WriteToLog = Redirectoutput("")
AT(1,0) "Formatting file $FileToFormat "
$WordDoc = CreateObject('Word.Application')
$AddTemplate = $WordDoc.Documents.Add($Template)
$WordDoc.Selection.InsertFile($PathAndFileToFormat)
$FormattedDoc = Substr($FileToFormat,1,Len($FileToFormat) -4)
$SaveWordDoc = $WordDoc.ActiveDocument.SaveAs("C:\Invoices\Docs\$FormattedDoc.doc",0)
$WordDoc.Quit(0)
$EmailIniFile = WriteProfileString("C:\Invoices\Email\SendMailTo.ini","$FiletoFormat","FileName","$FormattedDoc.doc")
$FileToFormat = Dir("")
Loop
$X = $X + 1
Loop

:KillTempTextFiles
AT(3,0) "Deleting temporary text files from C:\Invoices\Lofs..."
Shell '%Comspec% /c Echo y | Del "C:\Invoices\Lofs\*.*" 1>Nul 2>Nul'
If @Error = 0
AT(4,0) "Successfully deleted text files from C:\Invoices\Lofs..."
Else
AT(4,0) "Unable to delete text files from C:\Invoices\Lofs..."
EndIf

AT(6,0) "Deleting temporary text files from C:\Invoices\MiscInfo..."
Shell '%Comspec% /c Echo y | Del "C:\Invoices\MiscInfo\*.*" 1>Nul 2>Nul'
If @Error = 0
AT(7,0) "Successfully deleted text files from C:\Invoices\MiscInfo..."
Else
AT(7,0) "Unable to delete text files from C:\Invoices\MiscInfo..."
EndIf
$FileToProcess = "N"


:MoveFilesToServer1
Cls
? "Moving Docs to \\Server1\Share1\Invoices"
$FileToMove = Dir("C:\Invoices\Docs\*.doc")
While $FileToMove <> "" AND @ERROR = 0
$ProfileStringName = Substr($FileToMove,1,Len($FileToMove) - 4)
$ProfileStringName = "$ProfileStringName.txt"
Shell '%Comspec% /c Move "C:\Invoices\Docs\$FileToMove" "\\Server1\Share11\Invoices" 1>Nul 2>Nul'
If @Error = 0
$EmailIniFile = WriteProfileString("C:\Invoices\Email\SendMailTo.ini","$ProfileStringName","MovedTo","\\Server1\Share1\Invoices")
? "Successfully moved $FileToMove to \\Server1\Share11\Invoices"
$WriteToLog = Redirectoutput("C:\Invoices\Logs\Processed.Log")
? "@Date @Time Moved $FileToMove to \\Server1\Share11\Invoices"
$WriteToLog = Redirectoutput("")
Else
? "Unable to move $FileToMove to \\Server1\Share11\Invoices"
? "Attempting to move $FileToMove to C:\Invoices\NotMoved"
Shell '%Comspec% /c Move "C:\Invoices\Docs\$FileToMove" "C:\Invoices\CopyError" 1>Nul 2>Nul'
If @Error = 0
? "Successfully moved $FileToMove to C:\Invoices\CopyError"
$WriteToLog = Redirectoutput("C:\Invoices\Logs\Processed.Log")
? "@Date @Time Moved $FileToMove to C:\Invoices\CopyError"
$WriteToLog = Redirectoutput("")
$EmailIniFile = WriteProfileString("C:\Invoices\Email\SendMailTo.ini","$ProfileStringName","MovedTo","\\Server\c$\Invoices\NotMoved")
Else
? "Unable to move $FileToMove to C:\CopyError"
$WriteToLog = Redirectoutput("C:\Invoices\Logs\Processed.Log")
? "@Date @Time Unable to moved $FileToMove to C:\Invoices\CopyError"
$WriteToLog = Redirectoutput("")
$EmailIniFile = WriteProfileString("C:\Invoices\Email\SendMailTo.ini","$ProfileStringName","MovedTo","Not Moved")
EndIf
EndIf
$FileToMove = Dir("")
"@CRLF"
Loop
Sleep 5


:SendEmailNotification
Cls
If Exist("C:\Invoices\Email\SendMailTo.ini") = 1
If Open(1,"C:\Invoices\Email\SendMailTo.ini") = 0
$LineOfText = ReadLine(1)
While @Error = 0
Shell '%Comspec% /c Del C:\Invoices\Email\UserMsg.txt 1>Nul 2>Nul'
If Instr($LineOfText,".txt]") <> 0
$ProfileString = Substr($LineOfText,2,Len($LineOfText) - 6)
$ProfileString = "$ProfileString.txt"
$EmailToUser = ReadProfileString("C:\Invoices\Email\SendMailTo.Ini","$ProfileString","Userid")
$EmailToDistList = ReadProfileString("C:\Invoices\Email\SendMailTo.Ini","$ProfileString","DistList")
$EmailFileName = ReadProfileString("C:\Invoices\Email\SendMailTo.Ini","$ProfileString","FileName")
$EmailMovedTo = ReadProfileString("C:\Invoices\Email\SendMailTo.Ini","$ProfileString","MovedTo")
$EmailCycleName = ReadProfileString("C:\Invoices\Email\SendMailTo.Ini","$ProfileString","Cycle")

$WriteToUserMsg = Redirectoutput("C:\Invoices\Email\UserMsg.txt")
"Cycle $EmailToDistList has completed. Below is a link to your invoice file.@CRLF@CRLFPlease check the file for validity.@CRLF@CRLF$EmailMovedTo\$EmailFileName"
$WriteToUserMsg = Redirectoutput("")

? "@CRLFSending Email to $EmailToUser"
Shell '%Comspec% /c blat "C:\Invoices\Email\UserMsg.txt" -t me@@mydomain.com -s "Cycle $EmailCycleName is Complete." 1>Nul 2>Nul'
If @Error = 0
$WriteToLog = Redirectoutput("C:\Invoices\Logs\Processed.Log")
? "@Date @Time Sent email to $EmailToUser on $EmailFileName"
$WriteToLog = Redirectoutput("")
? "Email Successfully sent to $EmailToUser"
Else
$WriteToLog = Redirectoutput("C:\Invoices\Logs\Processed.Log")
? "@Date @Time UNABLE TO EMAIL $EmailToUser on $EmailFileName"
$WriteToLog = Redirectoutput("")
? "Unable to send email to $EmailToUser"
EndIf
Select
Case $DistList = "P1545IN1" $WriteToDistListMsg = Redirectoutput("C:\Invoices\Email\P1545IN1.txt")
Case $DistList = "P3507IN1" $WriteToDistListMsg = Redirectoutput("C:\Invoices\Email\P3507IN1.txt")
Case $DistList = "PQD62IN1" $WriteToDistListMsg = Redirectoutput("C:\Invoices\Email\PQD62IN1.txt")
Case $DistList = "PAISSIN1" $WriteToDistListMsg = Redirectoutput("C:\Invoices\Email\PAISSIN1.txt")
Case $DistList = "P3507DNM" $WriteToDistListMsg = Redirectoutput("C:\Invoices\Email\P3507DNM.txt")
EndSelect
$WriteToDistListMsg = Redirectoutput("C:\Invoices\Email\$EmailToDistList.txt")
? "$EmailMovedTo\$EmailFileName"
$WriteToDistListMsg = Redirectoutput("")
EndIf
$LineOfText = ReadLine(1)
Loop
$X = 0
While $X < 5
Select
Case $X = 0 $MailTo = "P1545IN1"
Case $X = 1 $MailTo = "P3507IN1"
Case $X = 2 $MailTo = "PQD62IN1"
Case $X = 3 $MailTo = "PAISSIN1"
Case $X = 4 $MailTo = "P3507DNM"
EndSelect
If Exist("C:\Invoices\Email\$MailTo.txt") = 1
? "@CRLFSending email to $MailTo."
Shell '%Comspec% /c blat "C:\Invoices\Email\$MailTo.txt" -t me@@mydomain.com -s "Cycle $MailTo is Complete." 1>Nul 2>Nul'
If @Error = 0
? "Successfully sent email to $MailTo"
$WriteToLog = Redirectoutput("C:\Invoices\Logs\Processed.Log")
? "@Date @Time Email Sent to $MailTo Distribution List"
$WriteToLog = Redirectoutput("")
Else
? "Unable to send email to $MailTo"
$WriteToLog = Redirectoutput("C:\Invoices\Logs\Processed.Log")
? "@Date @Time Unable to send email to $MailTo"
$WriteToLog = Redirectoutput("")
EndIf
EndIf
$X = $X + 1
Loop
EndIf
EndIf
$WriteToLog = Redirectoutput("C:\Invoices\Logs\Processed.Log")
? "@Date @Time Processing Finished for cycles"
$WriteToLog = Redirectoutput("")
Goto SearchForPVF

L8tr... [Big Grin]