StaffsLebowski
New Member
- Joined
- Nov 18, 2009
- Messages
- 22
Hi,
1: I have an Access DB that I use to copy Worksheets X, Y, Z from WorkBook 1 to WorkBook 2 (WorkBook 2 already has Sheets (A, B & C).
2: I save and close both WorkBooks.
3: WorkBook 2 then has sheets A, B & C and the imported X, Y and Z sheets
4: On the 'Workbook_SheetBeforeDoubleClick' event, I have a simple message box:
Msgbox Sh.Name
Msgbox Sh.CodeName
For Sheets A, B & C, when I double click a cell, I'm able to get both the Sheet.Name and the Sheet.CodeName but, for Sheets X, Y & Z, I'm only able to get the Sheet.Name
It's as if the 'sheets collection' has not been updated with the CodeName when the X, Y & Z sheets were imported. However, if I put a break-point on the first message box, and double click a cell on Sheets X, Y & Z then the CodeName is 'refreshed' and I'm able to return a value. It's as if, breaking into the code has forced Excel to refresh it's 'sheets collection'.
Does anyone know why this happens and more usefully, how to make sure the 'sheets collection' is up to date after importing new sheets?
Many thanks for your help,
Staffs Lebowski
1: I have an Access DB that I use to copy Worksheets X, Y, Z from WorkBook 1 to WorkBook 2 (WorkBook 2 already has Sheets (A, B & C).
objWBSource.Worksheets("MySheetName").Copy Before:=objWBDest.Sheets(1)
2: I save and close both WorkBooks.
3: WorkBook 2 then has sheets A, B & C and the imported X, Y and Z sheets
4: On the 'Workbook_SheetBeforeDoubleClick' event, I have a simple message box:
Msgbox Sh.Name
Msgbox Sh.CodeName
For Sheets A, B & C, when I double click a cell, I'm able to get both the Sheet.Name and the Sheet.CodeName but, for Sheets X, Y & Z, I'm only able to get the Sheet.Name
It's as if the 'sheets collection' has not been updated with the CodeName when the X, Y & Z sheets were imported. However, if I put a break-point on the first message box, and double click a cell on Sheets X, Y & Z then the CodeName is 'refreshed' and I'm able to return a value. It's as if, breaking into the code has forced Excel to refresh it's 'sheets collection'.
Does anyone know why this happens and more usefully, how to make sure the 'sheets collection' is up to date after importing new sheets?
Many thanks for your help,
Staffs Lebowski