Procedure Run Order

Procedure Run Order

Post by Alastair M » Fri, 21 Jan 2005 21:06:12


Dear All,

I have two procedures which should run one after another:

(a)Call CreateDlyBankSht - Sets up the workbook
(b)Call LockWorkBook - Locks the Workbook and certain
customisations.

I get an error stating that I cannot ammend cells because
the cells are locked. It looks as though the second
procedure is being run before the first one is complete.

Is there a way of telling Excel to undertake the first
procedure and complete it before the second procedure is
run?

Thanks again...

Alastair MacFarlane
 
 
 

Procedure Run Order

Post by Tom Ogilv » Fri, 21 Jan 2005 21:51:16

Code is usually executed sequentially

so

Sub Main()
Call CreateDlyBankSht
Call LockWorkBook
End sub

would normally insure what you ask. If using that approach doesn't work,
then you need to dig deeper into the working of your code and the state of
your workbook to identify the problem.

--
Regards,
Tom Ogilvy

 
 
 

Procedure Run Order

Post by Alastair M » Fri, 21 Jan 2005 22:00:06

Tom,

Thanks for the reply Tom, but that is the way I have it,
enclosed within the Workbook_Open Event. If I run the
procedures separately with one after another pressing F5,
there is no problem. It only happens when the procedures
are called one after another from another procedure/Event.
This would indicate to me that the first routine has not
completed before the second has run.

The first procedure copies values and calculates values
based on data imported from an external source. The second
locks these values so the user cannot change them.

Any further thoughts and thanks once again for your
response.

Alastair


approach doesn't work,
and the state of


another:
because
 
 
 

Procedure Run Order

Post by Tom Ogilv » Fri, 21 Jan 2005 22:38:31

The only thing that raises a flag is if you probably let your query run in
the background. You should change the setting so it runs in the foreground
and your code will wait for the query to complete.

--
Regards,
Tom Ogilvy
 
 
 

Procedure Run Order

Post by Alastair M » Sat, 22 Jan 2005 01:00:01

Thanks again Tom,

The problem seemed to be the order I ran the following
code:

ActiveWorkbook.Protect "TEST", Structure:=True,
Windows:=False
ActiveSheet.Protect "TEST", DrawingObjects:=True,
Contents:=True, Scenarios:=True

If I protected the sheet prior to activesheet the workbook
I would get an error, but when the other way round I would
get no error. Why? I don't know.

Thanks Tom


your query run in
in the foreground


F5,
procedure/Event.
second
code


complete.
first
procedure is
 
 
 

Procedure Run Order

Post by Tom Ogilv » Sat, 22 Jan 2005 04:08:05

Works either way for me. Tested both as a standalone code module and in the
workbook_open event of the workbook.

--
Regards,
Tom Ogilvy





"Alastair MacFarlane" < XXXX@XXXXX.COM > wrote in message
news:0b2201c4ff09$193356c0$ XXXX@XXXXX.COM ...