You can probably do what you want in Excel. See the following code that writes directly to a text file from Excel. You may be able to replace the text I have with the contents of cells in the workbook.
Sub CreateClearPrintQueueDotBatFile()
'This creates a text '.bat' file that clears the Windows print queue
'When the file is executed it needs 'Administrator' privileges to execute (VISTA)
'
'NOTE: This only creates a 'new' file. It will NOT OVERWRITE an existing file
'
'
'The contents of the file are (without the leading 'single quotes':
'
'@echo off
'if NOT exist %systemroot%\System32\spool\printers\*.s?? goto END
'net stop spooler
'if exist %systemroot%\System32\spool\printers\*.shd del %systemroot%\System32\spool\printers\*.shd /Q
'if exist %systemroot%\System32\spool\printers\*.spl del %systemroot%\System32\spool\printers\*.spl /Q
'net start spooler
':END
'exit
Const sFile = "ClearPrintQueue.bat"
Dim sTextFile As String
Dim iFileNo As Integer
Dim sPath As String
Dim sPathAndFile As String
'Get the path
sPath = ThisWorkbook.Path & "\"
'Create the full path and file name
sPathAndFile = sPath & sFile
'Create the file only if the file does not exist
If (Dir(sPathAndFile) = "") Then
'Allocate a file 'handle'
iFileNo = FreeFile
'Set error handler to close the file 'handle'
On Error GoTo CLOSEFILE
'Open the file for writing
Open sPathAndFile For Output As #iFileNo
'Write to the file
Print #iFileNo, "@echo off"
Print #iFileNo, "if NOT exist %systemroot%\System32\spool\printers\*.s?? echo The print queue is is empty."
Print #iFileNo, "if NOT exist %systemroot%\System32\spool\printers\*.s?? goto END"
Print #iFileNo, "net stop spooler"
Print #iFileNo, "echo Deleting files from the print queue."
Print #iFileNo, "if exist %systemroot%\System32\spool\printers\*.shd del %systemroot%\System32\spool\printers\*.shd /Q"
Print #iFileNo, "if exist %systemroot%\System32\spool\printers\*.spl del %systemroot%\System32\spool\printers\*.spl /Q"
Print #iFileNo, "net start spooler"
Print #iFileNo, ":END"
Print #iFileNo, "exit"
'Close the file
CLOSEFILE:
Close #iFileNo
On Error GoTo 0
End If
End Sub
Lewis
Bookmarks