Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

error with application.quit

Status
Not open for further replies.

dbsquared

Programmer
Nov 7, 2002
175
US
I am getting an error with the application.quit that is driving me nuts.
what I am doing is opening a data dump that I got from a screen capture and copying the data I want into a template. I then sort it and test to make sure there is something in the file otherwise I quit. This is where I keep getting a type mismatch error.
Can you help.

here is a snippet of the code:

Windows("Tellabs template.xls").Activate
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

Windows("DCCS.cap").Activate
Application.DisplayAlerts = False
ActiveWorkbook.Close

Cells.Select
Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

If Range("A1").Value = Empty Then
Application.Quit
End If

Any help as to why I keep getting the error would be appreciated.
To go where no programmer has gone before.
 
I'm presuming that the error ACTUALLY occurs on the line BEFORE:
If Range("A1").Value = Empty Then

There is no variable "Empty" - you have to use ISBLANK or =""
eg
If range("A1").text = "" then
application.quit


Rgds
Geoff

Vah! Denuone Latine loquebar? Me ineptum. Interdum modo elabitur
 
I get the same error with ="".
How do I use the isblank I got an error when I tried to add it to the code.

And actually the error is on the Application.quit. because as soon as I hit debug it quits excel. I can step through the code fine. The error shows up when I run it regularly. To go where no programmer has gone before.
 
I still get the error no matter how I format the If statement.
Anyone got any ideas?
Thanks To go where no programmer has gone before.
 
Since there is some confusion over which line is causing the error, I'd put another statement right above your application.quit, for example

msgbox "I'm here"

Could it be that you have
on error resume next
somewhere in the code above the snippet you're showing? In that case, the code may not trip over the error in the if statement, but catch up with you in the quit statement...
Rob
[flowerface]
 
Rob thanks for the response.

I have put other lines before the application.quit. It executes properly and shows the msgbox, then when I hit ok the error pops up.

There is no 'on error' statement in my code yet, I usually leave out error checking until the code is finished, and I can find most of the bugs.

I did put an 'on error resume next' in the code to see what would happen and the code went into an endless loop. Continually executing the same sub over and over again.

This is a funny error. probably a MS problem when testing blank cells. To go where no programmer has gone before.
 
Just one more suggestion, since this is such an odd problem - try to reverse the logic:

If Range(&quot;A1&quot;) <> &quot;&quot; Then goto SkipIt
Application.Quit
SkipIt:

Yes, I hate goto's as much as the next guy - this is just to make sure that the if is completely dealt with before the application.quit command.
By the way, you don't have a workbook_beforeclose event handler, do you? Or, even less likely, an application event handler?

Rob
[flowerface]
 
I tried your suggestionthe code just kept on going. As it should have. To answer your other questions I don't have any event handlers in the workbook or script. To go where no programmer has gone before.
 
Do you still have a problem, or does this (admittedly ugly) recoding get rid of the issue?
Rob
[flowerface]
 
I still have the problem. When I run the new coding it skips the application.quit and goes on if there is data in there. However if I need to close excel at this point which I still get the error.
To go where no programmer has gone before.
 
I think I have found the solution apparently in office xp when a cell is blank when you load it into a variable you have to prototype it hten you can test it. Very strange (obviously an Micoroslop problem.) To go where no programmer has gone before.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top