Closing an open workbook

G

Guest

Trying to close an open workbook that is not the active workbook. It was
opened for reference as a looked but after I obtain the information I need I
want to close it.

'working file
myFileName = Application.GetOpenFilename("Text Files, *.txt")

'refernce file
VMM_FileName = Application.GetOpenFilename("Text Files, *.txt")

code here...

'close reference file
Workbooks(VMM_FileName).Activate
ActiveWorkbook.Close False

With this I get Run-time error '9': Subscript out of range

Thanks
 
B

Bob Phillips

Try this

'working file
myFileName = Application.GetOpenFilename("Text Files, *.txt")

'refernce file
VMM_FileName = Application.GetOpenFilename("Text Files, *.txt")
Set VMM_WB = Worksbooks.open(VMM_Filename)

code here...

'close reference file
VMM_WB.Close False


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
G

Guest

For some reason thie created an error. When I changed it to

Set VMM_Workbook = ActiveWorkbook
.....
VMM_Workbook.Activate
ActiveWorkbook.Close False

This worked. Thanks
 
B

Bob Phillips

In my example it was VMM_WB not VMM_Workbook. Did you use that throughout,
and declare it as type Workbook?

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 

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

Top