Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi there
I'm having some trouble with a bit of VBA code, and its confusing me. The code is (something like) sThisBook = ActiveWorkbook.Name Set wkbSource = Workbooks.Open(sPath) If Len(sThisBook) 0 Then '... this makes the original workbook active Workbooks(sThisBook).Activate End If (I've precied it slightly) What I find is that: a) If I am running this code in the context of a new blank "Book1.xls" then after the other workbook has been opened only that book is open. i.e. workbooks.count is 1 and workbooks(1).name is the short version of the variable sPath Hence Workbooks(sThisBook).Activate fails with an error. Since its doing Workbooks("Book1.xls").Activate and that is no longer open. However, b) If I close book1 and click New so that I have "Book2.xls" then after the ..Open statement I have 2 workbooks and the .Activate does work since "Book2.xls" IS still open. Is Excel implicitly closing Book1 or am I missing something? Perplexed in England Rob |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Problem with Macro working in new workbooks that I open | Excel Programming | |||
Excel 2003 Workbooks.Open with CorruptLoad=xlRepairFile fails on Excel 5.0/95 file due to Chart, with Error 1004 Method 'Open' of object 'Workbooks' failed | Excel Programming | |||
Workbooks.Open Beeping Problem | Excel Programming | |||
Excel: workbooks.open problem | Excel Programming | |||
Workbooks.Open / .Open Text - How do you stop the .xls addition? | Excel Programming |