I want to see excel LOGS

leo89

New Member
Joined
Jul 29, 2011
Messages
4
Hello i have a macro that save my excel file each day at one period of time..but some time the macro does not work..or something is bugged..how can i see the LOGS for an excel file? to see what was the problem..cant find out whats make my macro..or my excel file stop..
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
There are no logs. You should keep track of your process execution, making your own log files. For instance, text files in a central directory.

Use statements like "On Error GoTo ..." to skip errors and not bring your procedures to an unexpected halt.
 
Upvote 0
Someting as simple as this would allow you to record events as your macros progress:-
Code:
[FONT=Fixedsys]Option Explicit[/FONT]
 
[FONT=Fixedsys]Sub WriteLog(ByVal sFile As String, ByVal sStatus As String)[/FONT]
 
[FONT=Fixedsys]  Dim intFH As Integer[/FONT]
 
[FONT=Fixedsys]  intFH = FreeFile[/FONT]
[FONT=Fixedsys]  Open sFile For Append As intFH[/FONT]
[FONT=Fixedsys]  Print #intFH, Format(Now(), "dd/mm/yyyy hh:nn:ss"); " "; sStatus[/FONT]
[FONT=Fixedsys]  Close intFH[/FONT]
 
[FONT=Fixedsys]End Sub[/FONT]
Every time you want to record something in a log file, you pass the name of the log file and the event you want to record to the subroutine and it will append the event to that file with a date/time-stamp.

For example, if you wanted to record when each macros starts and ends, you would place statements like this at the start and end of every macro:-
Code:
[FONT=Fixedsys]Public Sub MyMacro()[/FONT]
 
[FONT=Fixedsys]  Call WriteLog("c:\mylog.txt", "MyMacro started")[/FONT]
 
[FONT=Fixedsys][COLOR=green]  ' some code[/COLOR][/FONT]
 
[FONT=Fixedsys]  Call WriteLog("c:\mylog.txt", "MyMacro ended")[/FONT]
 
[FONT=Fixedsys]End Sub[/FONT]

If you wanted to record every time your macro went round a loop, you might do something like this:-
Code:
[FONT=Fixedsys]  For iRow = 2 To iLastRow[/FONT]
[FONT=Fixedsys]    Call WriteLog(Application.Path & "\logfile.txt", _[/FONT]
[FONT=Fixedsys]                  "Processing row " & iRow & ", column A = " & Cells(iRow, "A").Value)[/FONT]
[FONT=Fixedsys][COLOR=green]    ' some code[/COLOR][/FONT]
[FONT=Fixedsys]  Next iRow[/FONT]
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,728
Members
452,939
Latest member
WCrawford

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