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
 

Some videos you may like

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

Colo

MrExcel MVP,
Joined
Mar 20, 2002
Messages
1,456
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
 

gene_sc

New Member
Joined
Aug 24, 2002
Messages
32
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
 

Colo

MrExcel MVP,
Joined
Mar 20, 2002
Messages
1,456
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>
 

gene_sc

New Member
Joined
Aug 24, 2002
Messages
32
Hi Colo
Thanks :^)
I will give these a try.
I think this will help me, to learn VBA a little quicker
regards gene
 

Watch MrExcel Video

Forum statistics

Threads
1,122,912
Messages
5,598,828
Members
414,260
Latest member
joishe

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
Top