ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Method not run if code after Application.Run (https://www.excelbanter.com/excel-programming/419444-method-not-run-if-code-after-application-run.html)

Antonio

Method not run if code after Application.Run
 
The following code successfully opens a workbook and runs a method in that
workbook

Sub OpenAPS()

Const wb = "C:\Ats\Excel\APS.xls"

Workbooks.Open (wb)

Range("Server").Value = "abc1"

Application.Run ("APS.xls!Sheet4.subscribe")

End Sub


However, if I add more code after the Application.Run line the new code is
not run or, the APS.xls!Sheet4.subscribe method is not fully executed, which
leads to errors.

For example in

Sub OpenAPS()

Const wb = "C:\Ats\Excel\APS.xls"

Workbooks.Open (wb)

Range("Server").Value = "abc1"

Application.Run ("APS.xls!Sheet4.subscribe")

Call GetData

End Sub

The GetData sub is not executed.

The APS.xls!Sheet4.subscribe method takes a few seconds to execute fully.

I don't know if the reason is that the Call GetData is run before the
APS.xls!Sheet4.subscribe is run fully.

If so, how can I force a method to run only after a previous one is exited?

If that is not the reason, what is?

Thanks,

Antonio

Bob Phillips[_3_]

Method not run if code after Application.Run
 


--
__________________________________
HTH

Bob

"Antonio" wrote in message
...
The following code successfully opens a workbook and runs a method in that
workbook

Sub OpenAPS()

Const wb = "C:\Ats\Excel\APS.xls"

Workbooks.Open (wb)

Range("Server").Value = "abc1"

Application.Run ("APS.xls!Sheet4.subscribe")

End Sub


However, if I add more code after the Application.Run line the new code is
not run or, the APS.xls!Sheet4.subscribe method is not fully executed,
which
leads to errors.

For example in

Sub OpenAPS()

Const wb = "C:\Ats\Excel\APS.xls"

Workbooks.Open (wb)

Range("Server").Value = "abc1"

Application.Run ("APS.xls!Sheet4.subscribe")

Call GetData

End Sub

The GetData sub is not executed.

The APS.xls!Sheet4.subscribe method takes a few seconds to execute fully.

I don't know if the reason is that the Call GetData is run before the
APS.xls!Sheet4.subscribe is run fully.

If so, how can I force a method to run only after a previous one is
exited?

If that is not the reason, what is?

Thanks,

Antonio




Bob Phillips[_3_]

Method not run if code after Application.Run
 
You could use OnTime to issue the Getdata macro, say after 5 seconds.

--
__________________________________
HTH

Bob

"Antonio" wrote in message
...
The following code successfully opens a workbook and runs a method in that
workbook

Sub OpenAPS()

Const wb = "C:\Ats\Excel\APS.xls"

Workbooks.Open (wb)

Range("Server").Value = "abc1"

Application.Run ("APS.xls!Sheet4.subscribe")

End Sub


However, if I add more code after the Application.Run line the new code is
not run or, the APS.xls!Sheet4.subscribe method is not fully executed,
which
leads to errors.

For example in

Sub OpenAPS()

Const wb = "C:\Ats\Excel\APS.xls"

Workbooks.Open (wb)

Range("Server").Value = "abc1"

Application.Run ("APS.xls!Sheet4.subscribe")

Call GetData

End Sub

The GetData sub is not executed.

The APS.xls!Sheet4.subscribe method takes a few seconds to execute fully.

I don't know if the reason is that the Call GetData is run before the
APS.xls!Sheet4.subscribe is run fully.

If so, how can I force a method to run only after a previous one is
exited?

If that is not the reason, what is?

Thanks,

Antonio




Antonio

Method not run if code after Application.Run
 
Hello Bob,

Thank you for your help.

The OnTime works but it is not ideal.
Using Sleep, also works but it is not ideal.

The problem is that I do not know in advance how long to sleep the thread
for because the time it takes to run the application varies.

I do know that it has run as required when
Workbooks("APS.xls").Worksheets("4").Cells(40, 1) is not empty.

Consequently, I have tried:

While IsEmpty(Workbooks("APS.xls").Worksheets("4").Cells (40, 1))

Sleep (100)

Wend

GetData

However, the application get into an infinite loop, and it does not execute
GetData.

Thanks,

Antonio

"Bob Phillips" wrote:

You could use OnTime to issue the Getdata macro, say after 5 seconds.

--
__________________________________
HTH

Bob

"Antonio" wrote in message
...
The following code successfully opens a workbook and runs a method in that
workbook

Sub OpenAPS()

Const wb = "C:\Ats\Excel\APS.xls"

Workbooks.Open (wb)

Range("Server").Value = "abc1"

Application.Run ("APS.xls!Sheet4.subscribe")

End Sub


However, if I add more code after the Application.Run line the new code is
not run or, the APS.xls!Sheet4.subscribe method is not fully executed,
which
leads to errors.

For example in

Sub OpenAPS()

Const wb = "C:\Ats\Excel\APS.xls"

Workbooks.Open (wb)

Range("Server").Value = "abc1"

Application.Run ("APS.xls!Sheet4.subscribe")

Call GetData

End Sub

The GetData sub is not executed.

The APS.xls!Sheet4.subscribe method takes a few seconds to execute fully.

I don't know if the reason is that the Call GetData is run before the
APS.xls!Sheet4.subscribe is run fully.

If so, how can I force a method to run only after a previous one is
exited?

If that is not the reason, what is?

Thanks,

Antonio





Antonio

Method not run if code after Application.Run
 
As soon as I break the program (Ctrl + Break) the
Workbooks("APS.xls").Worksheets("4").Cells(40, 1) is populated

It seems again, that placing most code (the on time excluded) after
Application.Run ("APS.xls!Sheet4.subscribe") does not let the subscribe
rutine run



"Antonio" wrote:

Hello Bob,

Thank you for your help.

The OnTime works but it is not ideal.
Using Sleep, also works but it is not ideal.

The problem is that I do not know in advance how long to sleep the thread
for because the time it takes to run the application varies.

I do know that it has run as required when
Workbooks("APS.xls").Worksheets("4").Cells(40, 1) is not empty.

Consequently, I have tried:

While IsEmpty(Workbooks("APS.xls").Worksheets("4").Cells (40, 1))

Sleep (100)

Wend

GetData

However, the application get into an infinite loop, and it does not execute
GetData.

Thanks,

Antonio

"Bob Phillips" wrote:

You could use OnTime to issue the Getdata macro, say after 5 seconds.

--
__________________________________
HTH

Bob

"Antonio" wrote in message
...
The following code successfully opens a workbook and runs a method in that
workbook

Sub OpenAPS()

Const wb = "C:\Ats\Excel\APS.xls"

Workbooks.Open (wb)

Range("Server").Value = "abc1"

Application.Run ("APS.xls!Sheet4.subscribe")

End Sub


However, if I add more code after the Application.Run line the new code is
not run or, the APS.xls!Sheet4.subscribe method is not fully executed,
which
leads to errors.

For example in

Sub OpenAPS()

Const wb = "C:\Ats\Excel\APS.xls"

Workbooks.Open (wb)

Range("Server").Value = "abc1"

Application.Run ("APS.xls!Sheet4.subscribe")

Call GetData

End Sub

The GetData sub is not executed.

The APS.xls!Sheet4.subscribe method takes a few seconds to execute fully.

I don't know if the reason is that the Call GetData is run before the
APS.xls!Sheet4.subscribe is run fully.

If so, how can I force a method to run only after a previous one is
exited?

If that is not the reason, what is?

Thanks,

Antonio






All times are GMT +1. The time now is 05:23 PM.

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