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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Close object.workbook without saving

Status
Not open for further replies.

Fonzie

MIS
Feb 16, 2001
74
0
0
CA
I have the following code running from a button which is working fine, but it always prompts if I want to save changes to the excel file, which I do not. Is there anything I can add so it closes/quits the excel object without prompting to save?

Dim objXL As Object

Set objXL = CreateObject("Excel.Application")

objXL.workbooks.Open "c:\examples\test.xls"
objXL.range("a2").Value = Me.text1
Me.text2 = objXL.range("c4").Value
objXL.Quit
 
...
objXL.ActiveWorkbook.Saved = True
objXL.Quit

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
You should try setting your workbook up as a linked table rather than opening it.

If you want to keep it this way try

Code:
objXL.Quit acQuitSaveNone

Hope this helps,

Alex


Professor: But what about your superintelligence?
Gunther: When I had that there was too much pressure to use it. All I want out of life is to be a monkey of moderate intelligence who wears a suit. That's why I've decided to transfer to Business School.
Professor: NOOOOOOOOOOOO.
 
Alex, the Quit method of the Excel.Application object doesn't admit any parameter ...
 
PHV, I tried your suggestion and it worked fine for the example I posted. I then changed the code from a test excel doc to the production excel doc and I still get the message prompting to save changes. The difference between the two is I am changing the active worksheet. Do I need to do something different?

Dim objXL As Object

Set objXL = CreateObject("Excel.Application")

objXL.workbooks.Open "c:\examples\ProgCalc.xls"
objXL.worksheets(5).Activate
objXL.range("c6").Value = Me.itemA
objXL.range("c9").Value = Me.itemB
Me.Result = objXL.range("f15").Value
objXL.activeworkbook.saved = True
objXL.Quit
Set objXL = Nothing


Thanks again for your help
 
try
objXl.activeworkbook.close savechange:=true
objXl.application.quit
 
bubba, that gives me a 'Application-defined or object-defined error'
 
objXl.activeworkbook.close savechange:=true
 
objXL.ActiveWorkbook.Close False

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I still recieve the same error, but the error is on a line in the excel document, must be one of the macros. Can I disable the macros in my code somehow?
 
Can I disable the macros in my code somehow
IMO, it'd be better to make the excel's code more robust ...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top