How would I select output to a file or Debug?

T

Toby Erkson

I have a subroutine that outputs info about pivot tables and I would like the
option to either output the results to a file or to the Immediate window
(Debug.Print). This is the gist of what I'm looking for:

Sub (ToFile as Boolean)
If ToFile Then
Open "C:\PPI.log" For Output As #1
Else
Open Debug.Print for output as #1
End If
Print #1, "...output..."
..
..
..

Yes, the ELSE line does create an error which is why I'm asking. Is there a
form of redirection I can use? I'm looking for something easy, not a whole
gob of IF...THEN...ELSE statements :-o

TIA
 
G

Guest

Tony-

Have you tried your code without the "Open" in front of "Debug.Print"? As I
understand it, the keyword "Debug" is all you need send output to the Debug
(Immediate) window.

-Stan Shoemaker
Palo Alto, CA
 
D

Dave Peterson

I think I'd byte the bullet and do something like:

Sub (ToFile as Boolean)
If ToFile Then
Open "C:\PPI.log" For Output As #1 'maybe append???
Print #1, "...output1..."
Print #1, "...output2..."
close #1
Else
debug.print "...output1..."
debug.print "...output2..."
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top