Close a the current workbook and load another specified workbook

  • Thread starter Thread starter Adrian
  • Start date Start date
A

Adrian

Hi,

How do we code in VBA to close the current workbook and load another
specifed one?

For example, I am currently in ABC.xls and I wish to close this workbook and
load DEF.xls....
 
Activeworkbook.Close
Workbooks.Open filename:="C:\myDir\DEF.xls"

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Bob Phillips wrote
Activeworkbook.Close
Workbooks.Open filename:="C:\myDir\DEF.xls"

Will the second line really execute if the calling file is closed?
 
If the code isn't in the activeworkbook, it'll work ok.

(I'm guessing that there's a 3rd workbook controlling the action.)
 
Adrian,

Try something like

Sub AAA()
Workbooks.Open "DEF.xls"
Workbooks("ABC.xls").Close savechanges:=True
End Sub

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 

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