$home = "K:\Doctor Reports\"
$setup = "\\<server>\mis\reports\PArvu.txt"
$month = @monthno-1
IF $month = 0
$month = "12"
ELSE
If Len($month)<2
$month = "0"+$month
ENDIF
ENDIF
$year = IIf(@MONTHNO = 1, @YEAR-1, @YEAR)
;open txt file with tab names and email addresses
IF Open(1, $setup) = 0
$drfile = ReadLine(1)
ELSE
BEEP
? "Doc file not opened, error code: [" + @ERROR + "]"
sleep 5
EXIT
ENDIF
USE T: "\\<server2>\<dir>\123r4w"
;open Excel file
$app = CreateObject("Excel.Application")
;$app.visible = 1
;Create the Workbooks object
$wbs = $app.Workbooks
$rc = $wbs.Open("T:\Sherry\"+$drfile+".xls",0)
? "drfile = "+$drfile
$readerr = 0
;main program loop
WHILE $readerr = 0
$x = ReadLine(1)
$readerr = @ERROR
IF InStr($x, ",")
$x = Split($x, ",")
$doc = $x[0]
$folder = $x[1]
$drno = $x[2]
$spec = $x[3]
IF Len($doc)
? $doc
$dir = $home$folder
$file = $doc+"-Recap-"+$year+"-"+$month
$nul = WriteProfileString("C:\Program Files\pdf995\res\pdf995.ini","Parameters","Output File",$dir+"\Recap Reports\"+$file+".pdf")
$rc.Worksheets($doc).PrintOut(,,,,"PDF995")
sleep 3
$nul = WriteProfileString("C:\Program Files\pdf995\res\pdf995.ini","Parameters","Output File",$dir+"\(Current Month)\"+$file+".pdf")
$rc.Worksheets($doc).PrintOut(,,,,"PDF995")
sleep 3
Else
? "doc is blank"
ENDIF
ENDIF
LOOP
$nul = Close (1)
$nul = WriteProfileString("C:\Program Files\pdf995\res\pdf995.ini","Parameters","User File"," ")
$nul = WriteProfileString("C:\Program Files\pdf995\res\pdf995.ini","Parameters","Initial Dir"," ")
$nul = WriteProfileString("C:\Program Files\pdf995\res\pdf995.ini","Parameters","Launch"," ")
$nul = WriteProfileString("C:\Program Files\pdf995\res\pdf995.ini","Parameters","Output File"," ")
;IMPORTANT--YOU MUST CLOSE THE WORKBOOKS OBJECT OR ELSE
; THE EXCEL PROCESS WILL NOT TERMINATE!!!
$wbs.Close
;Destroy the Worksheet, Workbooks, and Application objects
$wbs = 0
$app = 0
USE LIST
USE T: /DELETE
USE LIST