LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default need logging before closing the workbook.

Hi
put the following code in your workbook module. You may have to change
the workbook/worksheet names and also have to adapt the specific
logging ranges to your needs:

-----

Option Explicit

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim log_wbk As Workbook
Dim log_wks As Worksheet
Dim last_log_row As Long
Dim path As String
Dim log_filename As String
Dim source_wbk As Workbook
Dim source_wks As Worksheet

'Initialization
Application.ScreenUpdating = False
path = "D:\Temp\" 'change this
log_filename = "logging.xls" 'change this
Set source_wbk = ActiveWorkbook
Set source_wks = source_wbk.Worksheets("Files") 'change this

'check if logging workbook is open / if not open it
On Error Resume Next
Set log_wbk = Workbooks(log_filename)
On Error GoTo 0
If log_wbk Is Nothing Then
Workbooks.Open filename:=path & log_filename
Set log_wbk = Workbooks(log_filename)
End If
Set log_wks = log_wbk.Worksheets("sheet1") 'change this

'get last used row
last_log_row = log_wks.Cells(Rows.Count, "A").End(xlUp).row

'log data - change to your needs
With log_wks
.Cells(last_log_row + 1, 1).Value = Application.UserName
.Cells(last_log_row + 1, 2).Value = Format(Now, "MM/DD/YYYY
hh:mm:ss")
.Cells(last_log_row + 1, 3).Value = source_wks.Range("A1").Value
.Cells(last_log_row + 1, 4).Value = source_wks.Range("B1").Value
.Cells(last_log_row + 1, 5).Value = source_wks.Range("C1").Value
End With


' save the changes
Application.DisplayAlerts = True
log_wbk.Save
log_wbk.Close
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub


------


--
Regards
Frank Kabel
Frankfurt, Germany

Martyn wrote:
I have workbook named "test.xls" which has various sheets.
The workbook is not protected and can be accessed by any
user on the network. I need to log spesific cell information
on a seperate xl workbook automatically (log.xls) without
any indication of the process each and every time before
the "test.xls" workbook is closed.
Here are the columns of "test.xls" that needs to be logged:
Sheet: 14 Cell: A4
Sheet: 14 Cell: A10
Sheet: 15 Cell: A9
Sheet: 12 Cell: A9
---------------------------
How should I code?
TIA


 
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
logging user name after viewing protected workbook Melanie New Users to Excel 8 August 17th 09 11:34 PM
Shared Workbook - User Not Logging Out John Excel Discussion (Misc queries) 0 February 6th 09 03:36 PM
Users stuck, not logging out of shared workbook Peter Excel Discussion (Misc queries) 1 January 4th 07 02:01 PM
Closing workbook Ed Excel Programming 4 February 6th 04 03:41 PM
closing excel after closing a workbook CWalsh[_2_] Excel Programming 3 January 21st 04 03:33 PM


All times are GMT +1. The time now is 01:55 PM.

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

About Us

"It's about Microsoft Excel"