PDA

View Full Version : sequential open and close workbooks



Daniel2001
02-25-2008, 05:03 AM
Hi I have two workbooks wkb1 ,wkb2,

I wanna open them at different scheduled time ,but application.ontime can only be written once in Excel.
so I am trying to open wkb1 on schedule time, then before it closes itself, wkb1 open wkb2. wkb2 will first close wkb1 ,then run the rest of the code. The problem is when wkb2 close wkb1, nothing continues...looks like everything stops as wkb1 closes

wkb1 code

Private Sub Workbook_Open()
Range("a1").Value = 1
Workbooks.Open Filename:="C:\wkb2.xls"
End Sub


wkb2 code


Private Sub Workbook_Open()

Dim wkb1 As Workbook

set wkb1 = workbooks("wkb1.xls")
wkb1.save
wkb1.close ' Here is where everything stops...the rest of the code doesn't run

Workbooks("wkb2.xls").Activate
ActiveSheet.Range("a1").Value = 2
ThisWorkbook.Close

End Sub

please advise on this:hi:

Bob Phillips
02-25-2008, 07:40 AM
You can create as many Ontimes as you want, there is no issue with that.

Or you could use application events to control it.

But simplest of all, don't close wkb1 in wkb2, wait until it opens and closes itself, then close wkb1. There seems no reason in your code for doing it the way you are.

MikeO
02-25-2008, 12:30 PM
The wkb1 code is still operating the Open command when wkb2 closes it. That's why everything stops at that point. You'll need to take a different approach.