Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to log Excel macro operations in a log file

Posted on 2013-02-06
4
Medium Priority
?
241 Views
Last Modified: 2013-12-14
I have made visual basic macros in an Excel which are run on Auto_Open. IS there a simple script available to log operations in the Excel file and possible error messages from macro operations to a log file?
0
Comment
Question by:ecgabrielsen
3 Comments
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 38858440
You would have to use a general routine for logging the error and call it from an error handler in each routine. If you want to log the routine name, you would have to hardcode that into the error handler for each routine too.
0
 
LVL 42

Accepted Solution

by:
Meir Rivkin earned 2000 total points
ID: 38858448
here's a simple log subroutine which accept log file name and data:
 
Sub Log(file As string, data As string)
    Const ForReading = 1, ForWriting = 2
    Dim FSO As Object, TS As Object, TextLine As String, FN As String
    
    FN = file
    Set FSO = CreateObject("Scripting.FileSystemObject")
    Set TS = FSO.OpenTextfile(FileName:=FN, IOMode:=ForAppending, Create:=True)
    TS.WriteLine data
  
    TS.Close
    Set TS = Nothing
    Set FSO = Nothing
End Sub

Open in new window

0
 
LVL 24

Expert Comment

by:Tracy
ID: 39718535
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question