Could it be done? Yeah, I bet so. But I wouldn't do it that way.
How about an alternative--just use the windows temp folder and you can clean it
up when you're doing regularly scheduled housekeeping:
Option Explicit
Dim myTextFileName As String
Sub runBoth()
Call fl
If Dir(myTextFileName) <> "" Then
Shell "start " & myTextFileName
'Application.Wait Now + TimeSerial(0, 0, 2)
'Kill myTextFileName
End If
End Sub
Sub fl()
Dim fd As Variant, ws As Worksheet, c As Range
myTextFileName = Environ("temp") & "\" & ActiveWorkbook.Name & ".fl.txt"
fd = FreeFile
Open myTextFileName For Output As #fd
On Error GoTo CleanUp
For Each ws In ActiveWorkbook.Worksheets
Print #fd, ws.Name
For Each c In ws.UsedRange
If c.HasFormula Then
Print #fd, c.Address(0, 0)
Print #fd, "", c.Formula
Print #fd, "", c.FormulaR1C1
Print #fd, ""
End If
Next c
Print #fd, "------------"
Print #fd, ""
Next ws
CleanUp:
Close #fd
End Sub
If you want to save the output, you can save it from notepad (or whatever
program you have associated with .txt files.)
I came back and added this:
Application.Wait Now + TimeSerial(0, 0, 2)
Kill myTextFileName
(and commented them out.)
in Win98 and using Notepad, I could delete that text file while it was open in
notepad.
I'm not sure if that'll work in all versions of windows or text editors. (I'm
kind of surprised that it worked at all.)