1. Visual Basic Code '------------------------------------------------------------------------------ Let XXDEVD$ = "MYPC" Let FLAG$ = "I:\RPTS\MYPC\FLAG.TXT" Let REPORT$ = "I:\RPTS\MYPC\QUERY1.CSV" Let REPORTSS$ = "I:\RPTS\MYPC\QUERY1.XLS" Let SheetNm1$ = "Query1.CSV" Let SheetNM2$ = "Query1" ‘ NOTE: Let Commands are like RPG's Eval statement. '--------------------------------------------------------------- ' Does the XLS file already exist from a previous run? FindIt = Dir(REPORTSS$) ' If the XLS file is found, delete it. If Not Len(FindIt) = 0 Then Kill REPORTSS$ End If '--------------------------------------------------------------- ' Does Flag.txt already exist from a previous run? FindIt = Dir(FLAG$) ' If Flag.txt is found, delete it. If Not Len(FindIt) = 0 Then Kill FLAG$ End If '--------------------------------------------------------------- ' Call the program on the AS/400 Let Shell1$ = "I:\Rpts\BatchXP\Query1.BAT" + " " + QueryNam + " " + QueryLib + " " + XXDEVD$ + " " + FromDt + " " + ToDate Shell (Shell1$) ‘ NOTE: The textboxes are named QueryNam, QueryLib, FromDt, and ToDate ‘ And Note: the + “ “ adds spaces to separate the parameters from each other '---------------------------------------------------------------- ' The following loop from While to Wend (Wend stands for While end) will keep ‘ Excel looping until the program on the AS/400 has completed. The loop will ‘ continue while the length of the FindIt variable is equal to 0. Excel ‘ will remain busy until it finds the file Flag.txt, thus making the ‘ length of FindIt > 0 and ending the loop. ' Check to see if Flag.txt can be found yet. FindIt = Dir(FLAG$) ' Keep checking to see if the length of FindIt variable is equal to 0. While Len(FindIt) = 0 FindIt = Dir(FLAG$) Wend ' Out of the FindIt loop - Flag.txt must have been found. ' So, Open the "Pushed Out" CSV file. Workbooks.Open Filename:=REPORT$ ' Activate the new CSV file and save it as an Excel Spreadsheet. Windows(SheetNm1$).Activate ActiveWorkbook.SaveAs Filename:=REPORTSS$, FileFormat:= _ xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _ , CreateBackup:=False ' Make the Headings font bold. Worksheets(SheetNM2$).Rows("1:2").Font.Bold = True ' Set the columns to the right width. Worksheets(SheetNM2$).Columns("A:IV").AutoFit ' Lock the titles so the headings won't scroll off the screen. Worksheets(SheetNM2$).Range("A3").Select ActiveWindow.FreezePanes = True