View Single Post
  #14   Report Post  
Posted to microsoft.public.excel.programming
Martyn Martyn is offline
external usenet poster
 
Posts: 80
Default need logging before closing the workbook.

Hi,

path variable is defined as String just as you have suggested
log.xls is located in (D:\Temp\)
But
I've tried a lot of alternatives too thus cannot find the cause...
I have tried replacing (D:\Temp\) with (C:\Temp\)
I have tried adding the path to all `log_filename` as well
but the result was the same.

If the log.xls file is not opened perior to execution of The macro, it stops
at this line

Set log_wbk = Workbooks(log_filename)
I am stuck
Martyn


"Frank Kabel" wrote in message
...
O.K. we are getting there.
So please double-check the following (you may post your results to this
NG):
- How is the path variable defined?
- In which directory is log.xls located

Try changing the first lines as following:

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\"
log_filename = "log.xls"
Set source_wbk = ActiveWorkbook


'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
msgbox path & log_filename
Workbooks.Open filename:=path & log_filename
exit sub
Set log_wbk = Workbooks(log_filename)
End If


and check if the log.xls workbook is open. If not something goes wrong
with the opening (wrong path, etc.)





--
Regards
Frank Kabel
Frankfurt, Germany

Martyn wrote:
Hi Frank,
Wow,...if I open log.xls before I start the logging macro everything
works smootly.
But I don't want the user to notice "log.xls "beeeing accesed neither
before start using "test.xls" nor after.
Martyn

"Frank Kabel" wrote in message
...
Hi Marty
to solve this error try the following:
1. Open log.xls before you start this logging macro and see if this
error stil exist
2. Enable screenupdating and insert a breakpoint after opening
log.xls and see if this workbook is really opened. If not probably
the workbook is not found

--
Regards
Frank Kabel
Frankfurt, Germany