ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Checking a workbook when it is opened (https://www.excelbanter.com/excel-programming/388265-checking-workbook-when-opened.html)

RobH

Checking a workbook when it is opened
 
I want Excel to check the data on every workbook that gets opened. If
certain criteria are met, then some processing will be carried out.

I have set up the event Workbook_Open to run, and this gets triggered
ok. I have a problem with this though. When I open an existing
workbook with Excel not previously running, the open routine gets
triggered twice. I guess that this is once for the PERSONAL.XLS
workbook and then again for the actual workbook. This is a problem,
as when it gets triggered the first time, the PERSONAL.XLS sheet is
hidden so if I try to look at anything on the sheet, the code falls
over.

Any assistance would be appreciate...

Rob


NickHK

Checking a workbook when it is opened
 
Rob,
Assuming something similar to Chip's method:
http://www.cpearson.com/excel/AppEvent.htm

check if the window is visible first:

Private Sub App_WorkbookOpen(ByVal Wb As Excel.Workbook)

If Wb.Windows(1).Visible = True Then
MsgBox "Application Event: WorkbookOpen: " & Wb.Name
Else
'Do nothing ?
End If

End Sub

NickHK

"RobH" wrote in message
oups.com...
I want Excel to check the data on every workbook that gets opened. If
certain criteria are met, then some processing will be carried out.

I have set up the event Workbook_Open to run, and this gets triggered
ok. I have a problem with this though. When I open an existing
workbook with Excel not previously running, the open routine gets
triggered twice. I guess that this is once for the PERSONAL.XLS
workbook and then again for the actual workbook. This is a problem,
as when it gets triggered the first time, the PERSONAL.XLS sheet is
hidden so if I try to look at anything on the sheet, the code falls
over.

Any assistance would be appreciate...

Rob




RobH

Checking a workbook when it is opened
 
On Apr 27, 9:00 am, "NickHK" wrote:
Rob,
Assuming something similar to Chip's method:http://www.cpearson.com/excel/AppEvent.htm

check if the window is visible first:

Private Sub App_WorkbookOpen(ByVal Wb As Excel.Workbook)

If Wb.Windows(1).Visible = True Then
MsgBox "Application Event: WorkbookOpen: " & Wb.Name
Else
'Do nothing ?
End If

End Sub

NickHK

"RobH" wrote in message

oups.com...



I want Excel to check the data on every workbook that gets opened. If
certain criteria are met, then some processing will be carried out.


I have set up the event Workbook_Open to run, and this gets triggered
ok. I have a problem with this though. When I open an existing
workbook with Excel not previously running, the open routine gets
triggered twice. I guess that this is once for the PERSONAL.XLS
workbook and then again for the actual workbook. This is a problem,
as when it gets triggered the first time, the PERSONAL.XLS sheet is
hidden so if I try to look at anything on the sheet, the code falls
over.


Any assistance would be appreciate...


Rob- Hide quoted text -


- Show quoted text -


Thanks NickHK, that worked a treat.

Rob



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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com