ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Code not working (https://www.excelbanter.com/excel-programming/381317-re-code-not-working.html)

NickHK

Code not working
 
Nigel,
If the WB has not been saved, I get the "do you want to save Book1 ?"
prompt, as expected.
Depending you want the changes committed or not, you can use:
ThisWorkbook.Save
or
ThisWorkbook.Saved = True

Otherwise the code as expected.

But this cannot be a copy/paste of your working code, as "application" would
be "Application" in the VBE.

NickHK

"Nigel" wrote in message
...
I use this code at the end of a report, everything works fine if I step

thru
the code and Excel will close but if I let the code run on its own it asks

me
if I want to Exit exit then just stops any ideas

TimeOutSeconds = 3

Set WSH = New IWshRuntimeLibrary.WshShell

Res = WSH.Popup("Do you want to Exit Excel?", TimeOutSeconds, "Exit Excel

",
vbYesNo)
Select Case Res
Case vbYes
application.Quit
Case vbNo
Exit Sub
Case -1
application.Quit
Case Else
End Select




Nigel

Code not working
 
That eact pice of code works in other spreadsheets I have, when I type in
Application it changes it to application, is a workbook save before this
portion of the text


"NickHK" wrote:

Nigel,
If the WB has not been saved, I get the "do you want to save Book1 ?"
prompt, as expected.
Depending you want the changes committed or not, you can use:
ThisWorkbook.Save
or
ThisWorkbook.Saved = True

Otherwise the code as expected.

But this cannot be a copy/paste of your working code, as "application" would
be "Application" in the VBE.

NickHK

"Nigel" wrote in message
...
I use this code at the end of a report, everything works fine if I step

thru
the code and Excel will close but if I let the code run on its own it asks

me
if I want to Exit exit then just stops any ideas

TimeOutSeconds = 3

Set WSH = New IWshRuntimeLibrary.WshShell

Res = WSH.Popup("Do you want to Exit Excel?", TimeOutSeconds, "Exit Excel

",
vbYesNo)
Select Case Res
Case vbYes
application.Quit
Case vbNo
Exit Sub
Case -1
application.Quit
Case Else
End Select





NickHK

Code not working
 
Nigel,
If you have "Application" changing to "application", that is a problem.
Have you declared a variable somewhere called "application" ?

NickHK

"Nigel" wrote in message
...
That eact pice of code works in other spreadsheets I have, when I type in
Application it changes it to application, is a workbook save before this
portion of the text


"NickHK" wrote:

Nigel,
If the WB has not been saved, I get the "do you want to save Book1 ?"
prompt, as expected.
Depending you want the changes committed or not, you can use:
ThisWorkbook.Save
or
ThisWorkbook.Saved = True

Otherwise the code as expected.

But this cannot be a copy/paste of your working code, as "application"

would
be "Application" in the VBE.

NickHK

"Nigel" wrote in message
...
I use this code at the end of a report, everything works fine if I

step
thru
the code and Excel will close but if I let the code run on its own it

asks
me
if I want to Exit exit then just stops any ideas

TimeOutSeconds = 3

Set WSH = New IWshRuntimeLibrary.WshShell

Res = WSH.Popup("Do you want to Exit Excel?", TimeOutSeconds, "Exit

Excel
",
vbYesNo)
Select Case Res
Case vbYes
application.Quit
Case vbNo
Exit Sub
Case -1
application.Quit
Case Else
End Select







Nigel

Code not working
 
It was declared as application in a module (essbase) and I have corrected it
t Applicaion, what I don't get is I have this exact same piece of code in
mutiple spreadsheets and it works in those but not this one



"NickHK" wrote:

Nigel,
If you have "Application" changing to "application", that is a problem.
Have you declared a variable somewhere called "application" ?

NickHK

"Nigel" wrote in message
...
That eact pice of code works in other spreadsheets I have, when I type in
Application it changes it to application, is a workbook save before this
portion of the text


"NickHK" wrote:

Nigel,
If the WB has not been saved, I get the "do you want to save Book1 ?"
prompt, as expected.
Depending you want the changes committed or not, you can use:
ThisWorkbook.Save
or
ThisWorkbook.Saved = True

Otherwise the code as expected.

But this cannot be a copy/paste of your working code, as "application"

would
be "Application" in the VBE.

NickHK

"Nigel" wrote in message
...
I use this code at the end of a report, everything works fine if I

step
thru
the code and Excel will close but if I let the code run on its own it

asks
me
if I want to Exit exit then just stops any ideas

TimeOutSeconds = 3

Set WSH = New IWshRuntimeLibrary.WshShell

Res = WSH.Popup("Do you want to Exit Excel?", TimeOutSeconds, "Exit

Excel
",
vbYesNo)
Select Case Res
Case vbYes
application.Quit
Case vbNo
Exit Sub
Case -1
application.Quit
Case Else
End Select







NickHK

Code not working
 
Nigel,
Maybe to do with the way Excel compiles on demand. If that offending code
was never compiled, then Excel did not know about that variable.
Whereas in this file, the "application" variable was compiled and hence led
to the error.

Could be wrong though..

NickHK

"Nigel" wrote in message
...
It was declared as application in a module (essbase) and I have corrected

it
t Applicaion, what I don't get is I have this exact same piece of code in
mutiple spreadsheets and it works in those but not this one



"NickHK" wrote:

Nigel,
If you have "Application" changing to "application", that is a problem.
Have you declared a variable somewhere called "application" ?

NickHK

"Nigel" wrote in message
...
That eact pice of code works in other spreadsheets I have, when I type

in
Application it changes it to application, is a workbook save before

this
portion of the text


"NickHK" wrote:

Nigel,
If the WB has not been saved, I get the "do you want to save Book1

?"
prompt, as expected.
Depending you want the changes committed or not, you can use:
ThisWorkbook.Save
or
ThisWorkbook.Saved = True

Otherwise the code as expected.

But this cannot be a copy/paste of your working code, as

"application"
would
be "Application" in the VBE.

NickHK

"Nigel" wrote in message
...
I use this code at the end of a report, everything works fine if I

step
thru
the code and Excel will close but if I let the code run on its own

it
asks
me
if I want to Exit exit then just stops any ideas

TimeOutSeconds = 3

Set WSH = New IWshRuntimeLibrary.WshShell

Res = WSH.Popup("Do you want to Exit Excel?", TimeOutSeconds,

"Exit
Excel
",
vbYesNo)
Select Case Res
Case vbYes
application.Quit
Case vbNo
Exit Sub
Case -1
application.Quit
Case Else
End Select









Nigel

Code not working
 
If I have the VB window open and press F5 to run the code it will work, if I
open the spreadsheet and let it go it will do everything but close excel

"NickHK" wrote:

Nigel,
Maybe to do with the way Excel compiles on demand. If that offending code
was never compiled, then Excel did not know about that variable.
Whereas in this file, the "application" variable was compiled and hence led
to the error.

Could be wrong though..

NickHK

"Nigel" wrote in message
...
It was declared as application in a module (essbase) and I have corrected

it
t Applicaion, what I don't get is I have this exact same piece of code in
mutiple spreadsheets and it works in those but not this one



"NickHK" wrote:

Nigel,
If you have "Application" changing to "application", that is a problem.
Have you declared a variable somewhere called "application" ?

NickHK

"Nigel" wrote in message
...
That eact pice of code works in other spreadsheets I have, when I type

in
Application it changes it to application, is a workbook save before

this
portion of the text


"NickHK" wrote:

Nigel,
If the WB has not been saved, I get the "do you want to save Book1

?"
prompt, as expected.
Depending you want the changes committed or not, you can use:
ThisWorkbook.Save
or
ThisWorkbook.Saved = True

Otherwise the code as expected.

But this cannot be a copy/paste of your working code, as

"application"
would
be "Application" in the VBE.

NickHK

"Nigel" wrote in message
...
I use this code at the end of a report, everything works fine if I
step
thru
the code and Excel will close but if I let the code run on its own

it
asks
me
if I want to Exit exit then just stops any ideas

TimeOutSeconds = 3

Set WSH = New IWshRuntimeLibrary.WshShell

Res = WSH.Popup("Do you want to Exit Excel?", TimeOutSeconds,

"Exit
Excel
",
vbYesNo)
Select Case Res
Case vbYes
application.Quit
Case vbNo
Exit Sub
Case -1
application.Quit
Case Else
End Select










NickHK

Code not working
 
Nigel,
As long as you have fixed that "application" variable problem, the code
works as expected for me.

If you add the line:
Debug.Print TypeName(Application), Application.Name
to you routine, what do you see in the immediate window ?

This article mentions some difficulties:
http://www.pcreview.co.uk/forums/thread-2038202.php

NickHK

"Nigel" wrote in message
...
If I have the VB window open and press F5 to run the code it will work, if

I
open the spreadsheet and let it go it will do everything but close excel

"NickHK" wrote:

Nigel,
Maybe to do with the way Excel compiles on demand. If that offending

code
was never compiled, then Excel did not know about that variable.
Whereas in this file, the "application" variable was compiled and hence

led
to the error.

Could be wrong though..

NickHK

"Nigel" wrote in message
...
It was declared as application in a module (essbase) and I have

corrected
it
t Applicaion, what I don't get is I have this exact same piece of code

in
mutiple spreadsheets and it works in those but not this one



"NickHK" wrote:

Nigel,
If you have "Application" changing to "application", that is a

problem.
Have you declared a variable somewhere called "application" ?

NickHK

"Nigel" wrote in message
...
That eact pice of code works in other spreadsheets I have, when I

type
in
Application it changes it to application, is a workbook save

before
this
portion of the text


"NickHK" wrote:

Nigel,
If the WB has not been saved, I get the "do you want to save

Book1
?"
prompt, as expected.
Depending you want the changes committed or not, you can use:
ThisWorkbook.Save
or
ThisWorkbook.Saved = True

Otherwise the code as expected.

But this cannot be a copy/paste of your working code, as

"application"
would
be "Application" in the VBE.

NickHK

"Nigel" wrote in message
...
I use this code at the end of a report, everything works fine

if I
step
thru
the code and Excel will close but if I let the code run on its

own
it
asks
me
if I want to Exit exit then just stops any ideas

TimeOutSeconds = 3

Set WSH = New IWshRuntimeLibrary.WshShell

Res = WSH.Popup("Do you want to Exit Excel?", TimeOutSeconds,

"Exit
Excel
",
vbYesNo)
Select Case Res
Case vbYes
application.Quit
Case vbNo
Exit Sub
Case -1
application.Quit
Case Else
End Select













All times are GMT +1. The time now is 06:49 AM.

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