Illegal operation after running Excel macro 
Author Message
 Illegal operation after running Excel macro

I'd be grateful for some help.
I have written an application that pastes some text into Excel and also
sends a macro to format that text.
My application has the option to keep the spreadsheet or just print and
discard the spreadsheet.
I set a variable called JustPrint to TRUE if the user just wants to print
and then discard the spreadsheet. In fact, with this option set, the user
never even sees Excel as I have turned off window updating and set
DisplayAllerts to FALSE.

However, the only problem is, that with JustPrint set to TRUE the
sprewadsheet prints OK, but on quitting Excel I get and "Illegal operation

I have discovered that I don't get this if I set DisplayAlerts to TRUE after
the line:

ActiveWorkbook.PrintOut Copies:=1, Collate:=True

but then I get the option to save the worksheet which I don't want!

I assume that the line application.quit is doing this. Any pointers to where
I'm going wrong?

Here's the code snippet which is the very final section of my macro:
if JustPrint then
  ActiveWorkbook.PrintOut Copies:=1, Collate:=True
  if NumPages=2 then
    Sheets("Duty Schedule Calendar 2").Move
    Sheets("Duty Schedule Calendar 1").Move
    Sheets("Duty Schedule Calendar").Move
  end if
application.DisplayAlerts = TRUE
...macro ends here


Sat, 09 Apr 2005 16:23:27 GMT  
 Illegal operation after running Excel macro

Try setting the displayalerts to true in the thisworkbook beforeclose sub.


Ken M

Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (
Version: 6.0.394 / Virus Database: 224 - Release Date: 03/Oct/02

Sun, 10 Apr 2005 06:36:03 GMT  
 [ 2 post ] 

 Relevant Pages 

1. Excel Automation (illegal operation)

2. Excel 97 illegal operation

3. Illegal operation printing embedded Excel chart

4. Illegal Operation using Excel 8.0 Objects from a VB application

5. Running a word Macro & an excel macro

6. Macros in Excel: How do I avoid getting confirmation windows when I run the macro

7. Opening an excel file through a form/running excel macros through access

8. Excel 2000 crashes when running macros created in Excel 97

9. Running an excel macro using excel 8 obj lib

10. need help: Open Excel, run macro, save file, close Excel

11. Running an excel macro using excel 8 obj lib

12. Illegal Operation


Powered by phpBB® Forum Software