#102122 - 2003-06-14 10:01 AM
Re: Open a created word doc, with a template...
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11629
Loc: CA
|
No one took up the gauntlet on this one eh!
Too bad. Hopefully soon someone will help out cmarti [ 14. June 2003, 10:02: Message edited by: NTDOC ]
|
|
Top
|
|
|
|
#102123 - 2003-06-14 10:57 PM
Re: Open a created word doc, with a template...
|
kholm
Korg Regular
   
Registered: 2000-06-19
Posts: 714
Loc: Randers, Denmark
|
I believe this is closer to your needs.
Insert text into another document, where document one is used as template.
The function InsertInTemplate() Can insert at the end of the template, or at a bookmark in the template.
If you want to insert the document at a bookmark in the template, use the optional parameter $InsertPoint, this should be the name of a valid bookmark name in the template.
Second optional parameter, can be used to save the new document with a new name, and if the extention is .dot the new document is saved as a template.
code:
Break On InsertInTemplate('E:\MiscInfo.dot','e:\invoices\miscinfo\mydoc.doc',,'e:\invoices\miscinfo\myNewdoc.doc') Function InsertInTemplate($Template,$Document,Optional $InsertPoint,Optional $NewName) Dim $oWord $oWord = CreateObject('Word.Application') $RC = $oWord.Documents.Add($Template) ; Create new document based on $Template If $InsertPoint $RC = $oWord.Selection.GoTo(-1,,,$InsertPoint) ; GoTo Bookmark Else $RC = $oWord.Selection.EndKey(6) ; GoTo EndOfDocument EndIf $oWord.Selection.InsertFile($Document) If Not $NewName $NewName = $Document ; Overwrite the original document if $NewName is empty EndIf If Right($NewName,4) = '.dot' $oWord.ActiveDocument.SaveAs($NewName, 1) ; Save as Template Else $oWord.ActiveDocument.SaveAs($NewName, 0) ; Save as Document EndIf $oWord.Quit(0) EndFunction
A template in Word is not just text, so my first suggestion was meant as pointing a document back to a valid template, this can be nessasary if the template contains macros. An example: In some of the Word-templates on my net i have a macro that substitutes the Print key in Word and ask the user for a journalnumber before the printout is done.
-Erik [ 14. June 2003, 23:13: Message edited by: kholm ]
|
|
Top
|
|
|
|
#102124 - 2003-06-16 09:56 AM
Re: Open a created word doc, with a template...
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11629
Loc: CA
|
Erik,
That's cool. I tested your code and it worked for me. Thanks for posting a solution.
My attempt may not be the best solution, but I think it would also work, if I had figured out how to switch between the documents in KiX code.
|
|
Top
|
|
|
|
#102125 - 2003-06-16 04:24 PM
Re: Open a created word doc, with a template...
|
cmarti
Hey THIS is FUN
Registered: 2001-02-26
Posts: 297
Loc: Little Rock, AR
|
Thanks for all the replies...
Kholm, I'll try your code and see how it works for me...I'll let you know what I find out..
Thanks..
|
|
Top
|
|
|
|
#102126 - 2003-06-16 04:50 PM
Re: Open a created word doc, with a template...
|
cmarti
Hey THIS is FUN
Registered: 2001-02-26
Posts: 297
Loc: Little Rock, AR
|
Kholm, it works exactly like I need it to!!!
Thank you, thank you!!! Thanks also to everyone else who spent time on this..
L8tr...
|
|
Top
|
|
|
|
#102127 - 2003-06-20 08:17 PM
Re: Open a created word doc, with a template...
|
cmarti
Hey THIS is FUN
Registered: 2001-02-26
Posts: 297
Loc: Little Rock, AR
|
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...
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...
|
|
Top
|
|
|
|
Moderator: Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 988 anonymous users online.
|
|
|