PDA

View Full Version : Exit Macro help



Hatake Kakashi
26-11-2007, 01:33 PM
I'm trying to create a macro that will save and exit an EXCEL 2007 Wookbook but I'm having problems doing it. I can make it save but I cannot get it to quit without an error occuring.
Anyway to get around it and make it save and exit without problems?

zeJosh
26-11-2007, 03:19 PM
It may come to help us, if we know which error that is?
On an assumed conclusion, i'd believe it might be a firewall error, although that should mean the program would not run.

Mentor
26-11-2007, 03:33 PM
As zeJosh said, without knowing what error your getting its hard to make suggestions?

zeJosh
26-11-2007, 05:25 PM
As i've said.
His firewall might be blocking the file type he's saving,
causing errors with the main executed program.

Hatake Kakashi
30-11-2007, 01:09 PM
The error isn't my firewall. I don't use the program at home because I don't have Office, only Word2007.
The macro runs but excel closes with an error "Microsoft Excel has encourtered a problem and needs to close".
I think it's because I'm typing the code incorrectely in the VB script.I have limited knowledge in coding (HTML is the only thingI knowbut vaguely) so I don't know what I can type in the VB macro editing.

DJ-Vimto
30-11-2007, 05:34 PM
if i remember rightly, all you need is "application.exit" along with the other parts of the code for the function you want to make the macro carry out.

what you may need to do, is loop it so that it doesnt try doing both at the same time.

i.e you need to make the code to tell the 'macro'..."save the worksheet, once saved, exit Excel"

its been well over 2 years since i last used VB properly so i cannot tell you the exact code to use

Hatake Kakashi
03-12-2007, 12:13 PM
Any code I try doesn't seem to work. all of them come back with that "Microsoft Excel has encourtered a problem" error.

I've tried:

Sub Save_Exit
ThisWorkbook.close SaveChanges:=True
End Sub

Sub Save_Exit ()
Wookbooks(filename).close SaveChanges:=True
End Sub

but all of them when run comes back with the error

craigg.
03-12-2007, 01:06 PM
Try:



Sub Save_Exit()
Application.Quit
ThisWorkbook.Close SaveChanges:=True
End Sub


Quite a while since I worked with macro's in Excel.

Hatake Kakashi
07-12-2007, 12:33 PM
I tried to use that code but excel errors when closing. I thought I had a solution but that errors after a few attempts. It works at first but stops working later on. I put the Application.Quit under ActiveWrokbook.Save (I made a save macro and added the application.quit line under it) but I don't want the system closing every other open workbook.
I'm not sure why it keeps erroring.

Want to hide these adverts? Register an account for free!