View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Steve Yandl[_3_] Steve Yandl[_3_] is offline
external usenet poster
 
Posts: 117
Default Output a string to the console?

Toby,

As I suggested in my earlier post, I suspect there is a more efficient way
to harvest output from the tasks your sheduler causes to execute. However,
if you do want text to a console window, here is an example. If you launch
this sub with some text as the argument, you get a command interpreter
console window (cmd.exe window) containing the text sent to the sub. If the
text argument is absent, you get the console window with "Hello World"

'----------------------------------------------
Sub StringInConsole(Optional strMsg As String = "")

If Not Len(strMsg) 0 Then
strMsg = "Hello World"
End If

strMsg = "echo " & strMsg & "&echo off"

Shell "cmd.exe /k" & strMsg, vbNormalFocus

End Sub
'----------------------------------------------

That you could launch with a sub like
'---------------------------------------------
Sub MessageMe()
StringInConsole("This is a test of this fine VBA routine")
End Sub
'---------------------------------------------
or
'---------------------------------------------
Sub MessageMe()
StringInConsole
End Sub
'---------------------------------------------

Steve Yandl




"Toby Erkson" wrote in message
...
Well, at least I'm consistent with asking the questions that can't be
answered, LOL
--
Toby Erkson
Excel 2003, WinXP

"Toby Erkson" wrote in message
...
I'm looking for a simple way to output to the console (command line
window?). Can this be done in VBA?

The reason: I have a scheduler that can monitor the task it has executed
and capture any console output for later inspection. I want this as I
would like to send text to the console when an error occurs to help me
figure things out. I don't want a log file.

If you're familiar with VBScripting then what I'm looking for is
something like this -- wscript.echo "Hello world!".

TIA!