PDA

View Full Version : Application.close information required



prshnthvn
03-28-2010, 07:22 AM
Hello Everyone,

Can anyone let me know how to close a chosen, opened workbook among all the other opened workbooks?

Actually i am opening a workbook(DATA1.xls) in my macro(calculator.xls) to get the data needed for my calculation. After copying the data from DATA1.xls, i want to close that workbook.

The workbook name can change so i cannot use workbooks(DATA1.xls).close always.
I am using a variable "DATA" while opening that workbook, is there any way to use this to close the workbook?

DATA = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls), *.xls", Title:="Please select a Master list file")

Thanks in advance;
Regards,
Prashanth.

Bob Phillips
03-28-2010, 07:41 AM
Set a public workbook variable when you open the workbook



DATA = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls), *.xls", Title:="Please select a Master list file")
Set wbData = Workbooks.open(DATA)

'do stuff

wbData.Close

prshnthvn
03-28-2010, 09:55 AM
Set a public workbook variable when you open the workbook



DATA = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls), *.xls", Title:="Please select a Master list file")
Set wbData = Workbooks.open(DATA)

'do stuff

wbData.Close


Thanks for the early reply xld,

But the above code did not work for some reason.
i tried something along your liines and it worked:beerchug:
Data = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls), *.xls", Title:="Please select the Master list file")
Workbooks.Open Filename:=MasterList
wb1 = ActiveWorkbook.Name
do stuff
Workbooks(wb1).Close

Regards,
Prashanth

mdmackillop
03-28-2010, 10:03 AM
Add Dim wbData as Workbook at the start of XLD's code