close file macro

  • Thread starter Thread starter Will Fleenor
  • Start date Start date
W

Will Fleenor

I need a macro that will open a file named DptBBudget.xls and close the
curent file named DptBBudget.xls. I have no problem with the file open part
using the Workbooks.Open Filename:= "DptBBudget.xls" command. I am having
a problem with the Workbooks.Close command which appears to close all the
open workbooks including the one I just opened.

Any help would be appreciated. I actually have a string of about 20
document I need to open, one just behind the other so figuring this out
would be very helpful. As I suspect you have figured out, I am not a
programmer (I am an accountant) and any help would be greatly appreciated.

Thanks, Will
Will Fleenor
 
Hi will

Use set in your code

Sub test()
Dim WB As Workbook
Set WB = Workbooks.Open("C\test.xls")
MsgBox "By"
WB.Close True ' false = not save and true = save
End Sub

Or if the workbook is active use this line

ActiveWorkbook.Close True ' false = not save and true = save
 
You can't have two workbooks open with the same name, so it is unclear how
you are not having trouble with Workbooks.Open.

While Open is qualified by Workbooks, close is qualified by a specific
workbook (unless you wanted to close all workbooks which it appears you
don't)

Workbooks("DptBBudget.xls").Close

would just close DptBBudget.xls
 
You didn't specify which book to close, so your statement closes all of them.

Workbooks("DptBBudget.xls").Close

See Help for the Close method for more information if you need it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top