Macro to open specific File

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a way to Create a macro to save current file and then Open a new
file, by specifying one for sure.
 
Try something like

Sub AAA()
ActiveWorkbook.Save
Workbooks.Open Filename:="C:\whatever.xls"
End Sub


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

Chip Pearson said:
Try something like

Sub AAA()
ActiveWorkbook.Save
Workbooks.Open Filename:="C:\whatever.xls"
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
Will this completely close the file before opening a new one? or do I need to
manually do that?
 
It doesn't close that other workbook.

But with the code in a third workbook:

Sub AAA()
ActiveWorkbook.close savechanges:=true
Workbooks.Open Filename:="C:\whatever.xls"
End Sub

(if the code is in the workbook that gets closed, then as soon as you close the
workbook, the macro will stop--so it won't open the "whatever.xls" workbook.)

One way around that is to open the new workbook and then close the other
workbook with the code in it.

Sub AAA()
Workbooks.Open Filename:="C:\whatever.xls"
ThisWorkbook.close savechanges:=true
End Sub
 

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