View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
PaulW PaulW is offline
external usenet poster
 
Posts: 130
Default Sheets() and Window() Objects not working?

First off, the macro:

Private Sub Workbook_Open()
Dim x As Integer
Application.ScreenUpdating = False
Workbooks.Open Filename:= _
"S:\Daily Reports\Add-ins\MI Log.xls"
x = Sheets("Sheet1").Range("A1").Value
Sheets("Sheet1").Cells(x, 1) = Environ("UserName")
Sheets("Sheet1").Cells(x, 2) = "Daily Figures (All)"
Sheets("Sheet1").Cells(x, 3) = Now()
Sheets("Sheet1").Range("A1") = Sheets("Sheet1").Range("A1").Value + 1

Windows("MI Log.xls").Close savechanges:=True
End Sub

In an effort to activily track which Management Information reports are
being used, who by, and how often, my idea was to add this bit of code into
every report. The idea being that every time someone opens a report the macro
triggers, opens the "MI Log.xls" and adds three peices of information, the
name of the person, which report they're using, and the time.

X is so I don't need to find a new line, and in A1 the spreadsheet has a
number showing the next new line.

The problem I have, is that this code gives two errors, one on the Sheets
and one on the Windows:

Run-Time Error '9'
Subscript out of range

I can remove the sheets, and hope in the future I don't want to make use of
the other sheets in MI Log.xls and forget to put it back to sheet one, but
i'm against using ActiveWindow.close as that has produced problems for me
before.

Can anyone think why these errors might be occuring? And how to fix them?