PDA

View Full Version : n00b needs help with workbook close



CDTech
02-18-2008, 11:48 AM
I can't for the life of me figure out how to close a workbook.

I build a string for the filespec and then:

Workbooks.Open sTempFileSpec

This works fine.

When I'm done with the temp file, I want to close it without save and that's where my code dies. Neither the MS help file nor Using Excel Visual Basic for Applications has made it clear to me where I'm going wrong. I've tried:

Workbooks.Close SaveChanges:=False, Filename:=sTempFileSpec, RouteWorkbook:=False

and

Workbook(SaveChanges:=False, Filename:=sTempFileSpec, RouteWorkbook:=False).Close

I get the impression from the help file that I should use just Workbooks.Close but I don't see how the particular workbook is specified.

I searched through this forum and while I found nothing exactly like I need I did see where a lot of folks create a workbook object and Set that, then close that workbook object.

I admit that VBA has not been an easy step for me :bug: after years of dabbling is "simpler" stuff like Lotus 1-2-3 for DOS and C. I've so far found only the Que book for Excel VBA and I still want something that provides a visual hierarchy of objects. Manipulating cells can be a huge pain in the rear -- sometimes you need a Range object, sometimes an ActiveCell, sometimes a sharp stick in the eye.

Thanks for any help.

Bob Phillips
02-18-2008, 12:04 PM
Activeworkbook.Close


or



Workbooks(sTempFileSpec).Close


depending upon the rest of the code and how full a name sTempFileSpec is.

CDTech
02-18-2008, 12:21 PM
Activeworkbook.Close means I need to activate it first? If I forget to do that the workbook with the code would close? That's why I'm trying to

sTempFileSpec is a complete URL to locate the workbook on a network share.

So it's that [Workbooks(sTempFileSpec).Close] simple? I do make changes in the temp file, I was wanting to prevent a save prompt when closing it. I saw in my search where others disabled alerts or warnings?

Again, thanks for ya'lls time.

Bob Phillips
02-18-2008, 12:32 PM
Then set an object to reference the workbook on opening, and close it by referencing that object.