ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Macro to open specific File (https://www.excelbanter.com/excel-discussion-misc-queries/26738-macro-open-specific-file.html)

tamato43

Macro to open specific File
 
Is there a way to Create a macro to save current file and then Open a new
file, by specifying one for sure.

Chip Pearson

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



"tamato43" wrote in message
...
Is there a way to Create a macro to save current file and then
Open a new
file, by specifying one for sure.




tamato43

Thanks

"Chip Pearson" wrote:

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



"tamato43" wrote in message
...
Is there a way to Create a macro to save current file and then
Open a new
file, by specifying one for sure.





tamato43

Will this completely close the file before opening a new one? or do I need to
manually do that?

"Chip Pearson" wrote:

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



"tamato43" wrote in message
...
Is there a way to Create a macro to save current file and then
Open a new
file, by specifying one for sure.





Dave Peterson

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

tamato43 wrote:

Will this completely close the file before opening a new one? or do I need to
manually do that?

"Chip Pearson" wrote:

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



"tamato43" wrote in message
...
Is there a way to Create a macro to save current file and then
Open a new
file, by specifying one for sure.





--

Dave Peterson


All times are GMT +1. The time now is 12:17 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com