Close a Workbook within a macro How?

eddy

Well-known Member
Joined
Mar 2, 2002
Messages
521
In the following code example
I am saving a workbook in directory Q:NEWQUOTESYSTEMQUOTES then taking information from three cells to produce the filename. As it stands the workbook is saved OK but then remains open even though I have opened another workbook in the macro. I want to save the workbook and then close the workbook ignoring any save as prompts etc.
Thanks Ted


Sub CopySheetSave()
'
' CopySheetSave Macro
' Macro recorded 03/03/2002 by Ted Pratt
'
'Save the quote
ActiveWorkbook.SaveAs Filename:="Q:NEWQUOTESYSTEMQUOTES" & Range("H1").Value & Range("I1").Value & Range("J1").Value

'This is where I want to close the above workbook


'After the save open mster sheet
Workbooks.Open Filename:="Q:NEWQUOTESYSTEMMasterQuoteSheet2.xls"

End Sub
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
On 2002-04-23 13:20, eddy wrote:
In the following code example
I am saving a workbook in directory Q:NEWQUOTESYSTEMQUOTES then taking information from three cells to produce the filename. As it stands the workbook is saved OK but then remains open even though I have opened another workbook in the macro. I want to save the workbook and then close the workbook ignoring any save as prompts etc.
Thanks Ted


Sub CopySheetSave()
'
' CopySheetSave Macro
' Macro recorded 03/03/2002 by Ted Pratt
'
'Save the quote
ActiveWorkbook.SaveAs Filename:="Q:NEWQUOTESYSTEMQUOTES" & Range("H1").Value & Range("I1").Value & Range("J1").Value

'This is where I want to close the above workbook


'After the save open mster sheet
Workbooks.Open Filename:="Q:NEWQUOTESYSTEMMasterQuoteSheet2.xls"

End Sub

Either put

ActiveWorkbook.Close

where you indicated it should go.

Or change the line

ActiveWorkbook.SaveAs Filename:="Q:NEWQUOTESYSTEMQUOTES" & Range("H1").Value & Range("I1").Value & Range("J1").Value

to

ActiveWorkbook.Close SaveChanges:=True, Filename:="Q:NEWQUOTESYSTEMQUOTES" & Range("H1").Value & Range("I1").Value & Range("J1").Value


HTH,
Jay
 
Upvote 0

Forum statistics

Threads
1,214,788
Messages
6,121,588
Members
449,039
Latest member
Arbind kumar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top