ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to close a workbook which contains the macro that's just been run? (https://www.excelbanter.com/excel-programming/314360-how-close-workbook-contains-macro-thats-just-been-run.html)

dead_girl

How to close a workbook which contains the macro that's just been run?
 

Hello~

I would like to be able to include a section of code in my macro to b
able to close the workbook in which the macro resides

I've tried the below section of code (in red):

Sub ReplaceNames()
<MY CODE
. . .

'Select a workbook to make active
Workbooks("Replace_All Names.xls").Activate
'Close active workbook
ActiveWorkbook.Close

End Sub

Note: the workbook which contains this macro is called "Replace_Al
Names.xls"

but this brings up the followng error message window:
"Microsoft Excel cannot find matching data to replace. No cell in th
selection contains what you typed, or no records match the criteria"

Are there any other alternatives??

:

--
dead_gir
-----------------------------------------------------------------------
dead_girl's Profile: http://www.excelforum.com/member.php...fo&userid=1559
View this thread: http://www.excelforum.com/showthread.php?threadid=27145


Ryan Poth

How to close a workbook which contains the macro that's just been
 
Dearly Departed,

It sounds like the error message you're getting isn't from the Close
statement, but from another statement in your code. Try stepping through the
code and I'm pretty sure you'll find the error is elsewhere.

HTH,
Ryan

"dead_girl" wrote:


Hello~

I would like to be able to include a section of code in my macro to be
able to close the workbook in which the macro resides

I've tried the below section of code (in red):

Sub ReplaceNames()
<MY CODE
. . .

'Select a workbook to make active
Workbooks("Replace_All Names.xls").Activate
'Close active workbook
ActiveWorkbook.Close

End Sub

Note: the workbook which contains this macro is called "Replace_All
Names.xls"

but this brings up the followng error message window:
"Microsoft Excel cannot find matching data to replace. No cell in the
selection contains what you typed, or no records match the criteria"

Are there any other alternatives??

:(


--
dead_girl
------------------------------------------------------------------------
dead_girl's Profile: http://www.excelforum.com/member.php...o&userid=15591
View this thread: http://www.excelforum.com/showthread...hreadid=271455




All times are GMT +1. The time now is 09:41 AM.

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