How to Write errors to log file?

gene_sc

New Member
Joined
Aug 24, 2002
Messages
32
Hi
Another newbe VBA question....
How can I Write errors to log file? I saw an example somewhere, but can't seem to find it
thanks
gene
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Hi gene,
Please check "Resume Next" out as follows. :biggrin:

<pre>
Sub test()
On Error GoTo WriteLog
Cells(0, 1).Select 'Error
MsgBox "Code is still running."
Exit Sub
WriteLog:
Debug.Print Err.Number & ":" & Err.Description
Resume Next
End Sub
</pre>

HTH
 
Upvote 0
Hi Thanks
I will try it out tonite, when I get home.
How can I set the path to save the log file?
regards gene
 
Upvote 0
Hi it's me again.

<pre>
Sub test2()
On Error GoTo WriteLog
Cells(0, 1).Select 'Error
MsgBox "Code is still running."
Exit Sub
WriteLog:
' // Please write fullpath where you want to set instead of ErrorLog.txt
' // EG. C:myfolderErrorLog.txt
Open "ErrorLog.txt" For Append As #1
Print #1, Now & " " & Err.Number & ":" & Err.Description
Close #1
Resume Next
End Sub
</pre>
 
Upvote 0
Hi Colo
Thanks :^)
I will give these a try.
I think this will help me, to learn VBA a little quicker
regards gene
 
Upvote 0

Forum statistics

Threads
1,218,750
Messages
6,144,281
Members
450,535
Latest member
Erlull

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top