ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Opening workbooks in sequence (https://www.excelbanter.com/excel-programming/295636-opening-workbooks-sequence.html)

matt

Opening workbooks in sequence
 
Hi All

I have a group of workbooks, each with a routine in the Auto_Open event. Upon opening the routine is executed and the workbook is saved (Using Workbooks("....").Close, True)

I have written a routine in a seperate parent workbook to take care of opening these in sequence. I have discovered that if you do not save the child workbooks then everything runs OK. However, if you exit the child workbooks and save them, the routine in the parent workbook halts. Is there a way around this

Thanks
Matt

Bob Phillips[_6_]

Opening workbooks in sequence
 
Matt,

A bit confused as to whether you are opening or closing. Is it the closing
that is failing because they have already been saved? If so, you could try
something like

On Error Resume Next
Set oWB = Workbooks("file1.xls")
If Not oWB Is Nothing Then
Workbooks("file1.xls").Close ,True
End If
'etc.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Matt" wrote in message
...
Hi All,

I have a group of workbooks, each with a routine in the Auto_Open event.

Upon opening the routine is executed and the workbook is saved (Using
Workbooks("....").Close, True)

I have written a routine in a seperate parent workbook to take care of

opening these in sequence. I have discovered that if you do not save the
child workbooks then everything runs OK. However, if you exit the child
workbooks and save them, the routine in the parent workbook halts. Is there
a way around this?

Thanks,
Matt




matt

Opening workbooks in sequence
 
Sorry (That confused me too when I read it back

I have a main workbook and it has a routine which opens other workbooks in sequence

Workbooks.open("Workbook1"
Workbooks.Open("Workbook2")

et

In the Open event of each of these workbooks is a routine. If you don't put code to close/save these workbooks at the end of the routine then each workbook opens OK. If you place code to close and save the workbooks at the end of the routine then the routine in the main book doesn't go any further.

Thanks
Matt

Bob Phillips[_6_]

Opening workbooks in sequence
 
Hi Matt,

I see what you mean now. When the called WB closes, the code thread is lost
with it, so the original code does not continue. Don't think there is much
you can do about that other move the code that is in the child workbooks
from the Workbook_Open event to an Auto_Open macro because Auto_open doesn't
fire when a workbook is opened from code.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Matt" wrote in message
...
Sorry (That confused me too when I read it back)

I have a main workbook and it has a routine which opens other workbooks in

sequence.

Workbooks.open("Workbook1")
Workbooks.Open("Workbook2")

etc

In the Open event of each of these workbooks is a routine. If you don't

put code to close/save these workbooks at the end of the routine then each
workbook opens OK. If you place code to close and save the workbooks at the
end of the routine then the routine in the main book doesn't go any further.

Thanks,
Matt





All times are GMT +1. The time now is 04:24 AM.

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