Solved

How to log Excel macro operations in a log file

Posted on 2013-02-06
4
210 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
4 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:
sedgwick earned 500 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:broomee9
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

829 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