Output a string to the console?

  • Thread starter Thread starter Toby Erkson
  • Start date Start date
T

Toby Erkson

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!
 
HI

Maybe this is what you need.
You can output to the Immediate window, which you can see in the VBA editor.

Debug.Print "Hello world"

Regards,
Per
 
Nope, since the workbook is executed automatically by the scheduler the
Immediate Window won't do me any good. The workbook is only seen by a human
when there's an error and the errors are generally due to the input file and
not the workbook.
 
Wow, cool Steve!

That works well for a single line of output but I would need the ability to
output as the program moves along, just like a log file. As is, this opens
a new command window every time it's called. Maybe I could make it into an
object... I'll play some more with it. Thanks for the assistance :-)
 
Well, I was hoping to not have to build a string. The goal is to simply
open the command window and spit out text as the program plods along instead
of waiting until it finishes (for better or for worse) to output a built-up
string because that would require error checking code, which is something
I'd like to avoid. Remember, the scheduler app. I use captures the command
window output as the executing program runs so if the executing program
fails for any reason -- be it gracefully or catastrophically -- the [saved]
command window text would show me the last point of noted execution.

Background: The person I replaced wrote many scripts and VBA code but w/o
good error trapping. Right now it's faster for me to put in these sort of
"echo" statements at key points in the VBA code than set up error
trapping -- that would be a long task with too small of a return. This
method would give me a better idea where the error occurred instead of just
"somewhere in this workbook" and it would allow me to insert break points in
appropriate locations. As I come across the rare error I add my error
checking/trapping as necessary.
 
Back
Top