Quiting Excel without Saving

Dec 22, 2011 at 5:02pm
I'm trying to make a program that takes info from Excel. So far so good but when it finishes Excel always asks me if I want to save. I use close(); to get out of Excel but when I tried to find the 'don't save' arguements on the interget the Visual C++ Express assembler tells me that close doesn't take 1, 2, or even 3 arguements. Does anybody have familiarity with this issue and can help me?
Dec 22, 2011 at 5:14pm
How are you controlling Excel? OLE Automation?
Dec 22, 2011 at 5:22pm
Not OLE Automation. I'm using COM interface, or at least I hope that's what it's called.

My work found out that I'd taken some programming classes six years ago and decided to see what I could do during our businesses down time. I'm struggling with this and frankly, most of it is a Frankenstein program from various parts of the web.
Dec 22, 2011 at 5:29pm
What is the purpose of your program? If you're trying to manipulate Microsoft Office only, you might be better off just using the inherent VBA Scripting language. I was actually in a very similar situation as you for a while.
Dec 22, 2011 at 5:37pm
Yes, that's automation.

I believe you can set the workbook's Saved property to VARIANT_TRUE and then Close() it, or even Quit() Excel.
Dec 22, 2011 at 5:42pm
The problem is that I remember most of the stuff from my Introduction to C++ class but I've never touched VBA and have no clue how it works.

I'm basically having my program open seven different Excel workbooks, copy some information from specific cells, and then manually type it out into our database software (which the program opens as well.)

I've got the program to work like a champ with two issues. It fouls up when it switches to the second workbook (working on that) and I can't figure out how to get it to close a workbook without saving. I'm even wondering if the two might be related (won't open a second workbook while the other is mid-closing or some such.)
Dec 22, 2011 at 8:18pm
then manually type it out into our database software


Have you got a robot hand wired up to your computer???
Dec 22, 2011 at 8:23pm
I suspect that most of the problem that you're having is in interfacing between C++ and the native language of Microsoft scripting, which as I said earlier is VBA. If you convert your project to VBA, I think that you'll find that a few days of research will have you well placed to perform your function. On the other hand, you could always contact me by PM, and I could do it for you, but I would charge your company.
Dec 22, 2011 at 8:24pm
When I say manually, I mean that I'm using commands to simulate keystrokes.
Dec 22, 2011 at 8:31pm
He's not interfacing with VBA at all. He's using Automation to control Excel. Like I said, setting Saved to true should do the trick just fine. You can look up the documentation in MSDN (search for workbook.saved).
Dec 22, 2011 at 10:25pm
Thanks webJose, that solved my problem completely. My other problem just needed me to move the goto point down 1 line (bah!)

Besides some good commenting, and tightening up, that actually concludes this project that I've been working on for about 3 weeks at work. Go me.
Topic archived. No new replies allowed.