Re: Sending debugging messages to a second document.

Tech-Archive recommends: Fix windows errors by optimizing your registry



Instead of opening the log file at the beginning of the macro, writing a
bunch of lines, and closing the log file at the end of the macro, you'll
have to open/write/close for each log message. Normally this would be too
resource-intensive, but in this case it's necessary because VBA doesn't have
any sort of "flush buffer" method other than Close.

This will require using For Append in the Open statement instead of For
Output, to avoid clearing the file each time.

It would probably be best to write this as a subroutine that takes the log
message as a parameter (and possibly the filename of the log, if you want it
to be generally reusable).

Barry wrote:
Jay:

With some minor modification, your example code is working, up to a
point. Apparently the OS or Word or something is buffering the writes
to the log file. By the time the macro hangs, only a small portion
of the trace statements have been written out; the rest are lost when
the hang occurrs.

Can you tell me how to force immediate writes to the log file, so
that I don't lose state of the macro at the time or the error?

Thank you for your help.


Barry wrote:
I am debugging a VBA subroutine that hangs under certain conditions.
In order to pinpoint the spot in the code where the hang occurs, I
want to write trace data to a second document, where they will not
interfere with the text and ActiveX controls being added to the
target document. I know that this is pretty elementary VBA, but
I've never done it before and can't seem to make it work.

Can someone show me or point me to an example of how this is done?
Thanks in advance for any help.

See this thread from yesterday:
http://groups.google.com/group/microsoft.public.word.vba.beginners/browse_thread/thread/c0e61d07da657f08/2d848ae91240c9ea?hl=en&lnk=st&q=#2d848ae91240c9ea

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.


.



Relevant Pages

  • Re: Word document doing a disappearing act
    ... we run a macro I ... past couple of weeks) the log file just disappears, ... instead, Word displays its own error message, asking to reconnect to ...
    (microsoft.public.word.vba.general)
  • Word document doing a disappearing act
    ... past couple of weeks) the log file just disappears, ... The macro in question contains a loop where, if there's an error opening the ... instead, Word displays its own error message, asking to reconnect to the ... This is the Amazing Disappearing File. ...
    (microsoft.public.word.vba.general)
  • Re: Changing a file extension
    ... Given below is the macro I have. ... It looks for *.xls files in a folder ... Fnum = Fnum + 1 ... the *.log file as A and B. I guess this is possible only if the log ...
    (microsoft.public.excel.programming)
  • Re: Changing a file extension
    ... Here's a simple macro to read a delimited text file named "MyLog.Log" in the current folder. ... All the values are stored in an array from which you can populate your destination worksheet. ... its not working with *.log file. ... have references the column A and B of the excel file. ...
    (microsoft.public.excel.programming)
  • Re: Changing a file extension
    ... You should probably share your macro as it is now and explain what you want ... If you have file names listed in a workbook or a text file ... its not working with *.log file. ... have references the column A and B of the excel file. ...
    (microsoft.public.excel.programming)