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.
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.