Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Log to a file everytime I open a spreadsheet

I would like a VBA macro to log to a file every spreadsheet I open.

Is it possible in VBA ?

Can I have a macro to fire when a spreadsheet is open to log the
filepath+filename to a file ? Most of the spreadsheets I run are from
external sources, and do not contain macros

Cheers
Jim
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Log to a file everytime I open a spreadsheet

You could log all workbook events, including "Open" from your Personal xls
or some addin. Try the following in (say) your personal

Insert a Class module, rename it from Class1 to "clsAppEvents"

Add following code in clsAppEvents, ThisWorkbook module and in a normal
module as indicated -


'' Class named clsAppEvents

Public WithEvents xlApp As Excel.Application

Private Sub xlApp_WorkbookOpen(ByVal Wb As Workbook)
LogFileOpen Wb.FullName
End Sub


Sub LogFileOpen(sFullName As String)
Dim iFF As Integer
Dim sText As String
Dim sFile As String
Const cPATH As String = "c:\temp\" ' < change to suit
Const cLOG As String = "LogWorkbooks.txt" ' < change to suit

On Error GoTo errH
sFile = cPATH & cLOG

sText = Now & " " & vbTab & sFullName
iFF = FreeFile
Open sFile For Append As #iFF
Print #iFF, sText
done:
On Error Resume Next
Close #iFF
Exit Sub

errH:
Debug.Print "LogFileOpen error: " & Err.Description
Resume done
End Sub


'' in ThisWorkbook module

Private Sub Workbook_Open()
SetAppEvents
End Sub


' in a normal module
Private mClsEvnts As clsAppEvents

Sub SetAppEvents()
Set mClsEvnts = New clsAppEvents
Set mClsEvnts.xlApp = Application
End Sub



For testing, manually run SetAppEvents; this will create an instance of the
class to trap Application level events.

Open some workbooks and look at LogWorkbooks.txt

Assuming all appears to be working as expected, in future SetAppEvents will
be called from Workbook_Open when Personal.xls opens.

If you edit any of the code you'll need to run SetAppEvents again.

Regards,
Peter T


"Roshintosh" wrote in message
...
I would like a VBA macro to log to a file every spreadsheet I open.

Is it possible in VBA ?

Can I have a macro to fire when a spreadsheet is open to log the
filepath+filename to a file ? Most of the spreadsheets I run are from
external sources, and do not contain macros

Cheers
Jim



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Chart looses format everytime I open the file Pana Charts and Charting in Excel 0 May 14th 09 07:31 PM
how can I open an excel file everytime on certain sheet? Inas Excel Discussion (Misc queries) 1 June 7th 07 12:28 PM
EULA pops up everytime I open an Excel file in 2003 ver lbl Excel Discussion (Misc queries) 0 August 11th 06 04:11 PM
How do I set up an excel doc. to open on the same tab everytime Dana Stricker Excel Discussion (Misc queries) 2 November 17th 05 07:54 PM


All times are GMT +1. The time now is 03:40 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"