View Single Post
  #21   Report Post  
Posted to microsoft.public.excel.programming
Frank Kabel Frank Kabel is offline
external usenet poster
 
Posts: 3,885
Default need logging before closing the workbook.

Hi Marty
now i see but this line should not throw an error (as this should be
prevented by the line: 'on error resume next'). As a workaround you may
comment these 3 lines (if you're sure that the log.xls file is not
opened manually by a user). Your code should work then. But I'm still
curious why this error is not catched by the 'on error resume next'
line.

--
Regards
Frank Kabel
Frankfurt, Germany

Martyn wrote:
Hi Frank,

I am totally confused too...Also am starting to feel like a fool!
The problem occurs while it's checking if the log file is open and
open it if not...
So the macro is not even getting to the line related with the
msgbox... Problem happens before that...He
--------------
'check if logging workbook is open / if not open it
On Error Resume Next
Set log_wbk = Workbooks(log_filename)
On Error GoTo 0
--------------
The error message I receive is exactly this:
Run-time error '9'
Subscript out of range

And the VBA editor highlights the line

Set log_wbk = Workbooks(log_filename)

Hope we can get somewhere now.
Cheers
Martyn



"Frank Kabel" wrote in message
...
Hi Martyn
now I'm getting desperate :-)
If the path variable is declared as path="C:\"
and the lo´g_filename as
log_filename = "log.xls"

then the code snippet
If log_wbk Is Nothing Then
msgbox path & log_filename
Workbooks.Open filename:=path & log_filename
Set log_wbk = Workbooks(log_filename)
End If

should do. Does this msgbox returns the correct information?. I have
tested this again in my environment and everything works fine - also
took it to another PC - result was also o.k.

--
Regards
Frank Kabel
Frankfurt, Germany