ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Closing Workbooks Formula (https://www.excelbanter.com/excel-programming/367424-closing-workbooks-formula.html)

bodhisatvaofboogie

Closing Workbooks Formula
 
Windows("Book1").Close savechanges:=False
Windows("Book2").Activate
Cells.Select
Selection.Cut
Windows("Book2").ActivateNext
Range("A1").Select
ActiveSheet.Paste
Windows("Book2").Close savechanges:=False

This is the formula I am using to close my extra workbooks. Is there a way
I can do this without the specific ("Book2") or ("Book1")??? Because that
makes it so the only way this macro will run is by closing down excel and
restarting it. I wanted to do the same thing without naming specific
workbooks. SO, the macro opens a total of three workbooks:

"Original Name of File being opened"
"Workbook1"
"Workbook2"

So how do I jumb between workbooks and activate them without naming them
specifically then ultimately close them. THANKS!!!!

[email protected]

Closing Workbooks Formula
 
You can use this code at the end of the macro

For Each w In Workbooks
If w.Name < ThisWorkbook.Name Then
w.Close savechanges:=True
End If
Next w

I hope this helps.
Regards

bodhisatvaofboogie ha escrito:

Windows("Book1").Close savechanges:=False
Windows("Book2").Activate
Cells.Select
Selection.Cut
Windows("Book2").ActivateNext
Range("A1").Select
ActiveSheet.Paste
Windows("Book2").Close savechanges:=False

This is the formula I am using to close my extra workbooks. Is there a way
I can do this without the specific ("Book2") or ("Book1")??? Because that
makes it so the only way this macro will run is by closing down excel and
restarting it. I wanted to do the same thing without naming specific
workbooks. SO, the macro opens a total of three workbooks:

"Original Name of File being opened"
"Workbook1"
"Workbook2"

So how do I jumb between workbooks and activate them without naming them
specifically then ultimately close them. THANKS!!!!



bodhisatvaofboogie

Closing Workbooks Formula
 
Well I thought about using that, BUT, that would close down everything else.
So just for a hypothetical situation:

person A is working in Excel. Person A wishes to run this macro and not
bother with closing down current work. -- This is not possible due to the
current limitations of the macro. If I were to make the changes in it so all
other workbooks would close then the stuff person A didn't want closed would
be shut down anyway. SO, how do I just shut down the ones I want? How about
this?

Is there a way to change the name of the workbook with a code, because if I
could do that, then I would just plug that into the macro at all appropriate
spots, then when it comes time to close down the extras, I can input the
names that I have them changed to. So how do I change the names of the
workbook with a code?

THANKS!!!

" wrote:

You can use this code at the end of the macro

For Each w In Workbooks
If w.Name < ThisWorkbook.Name Then
w.Close savechanges:=True
End If
Next w

I hope this helps.
Regards

bodhisatvaofboogie ha escrito:

Windows("Book1").Close savechanges:=False
Windows("Book2").Activate
Cells.Select
Selection.Cut
Windows("Book2").ActivateNext
Range("A1").Select
ActiveSheet.Paste
Windows("Book2").Close savechanges:=False

This is the formula I am using to close my extra workbooks. Is there a way
I can do this without the specific ("Book2") or ("Book1")??? Because that
makes it so the only way this macro will run is by closing down excel and
restarting it. I wanted to do the same thing without naming specific
workbooks. SO, the macro opens a total of three workbooks:

"Original Name of File being opened"
"Workbook1"
"Workbook2"

So how do I jumb between workbooks and activate them without naming them
specifically then ultimately close them. THANKS!!!!




Die_Another_Day

Closing Workbooks Formula
 
I don't understand why you have to restart xl in the first place. Maybe
we can fix this.

Die_Another_Day
bodhisatvaofboogie wrote:
Windows("Book1").Close savechanges:=False
Windows("Book2").Activate
Cells.Select
Selection.Cut
Windows("Book2").ActivateNext
Range("A1").Select
ActiveSheet.Paste
Windows("Book2").Close savechanges:=False

This is the formula I am using to close my extra workbooks. Is there a way
I can do this without the specific ("Book2") or ("Book1")??? Because that
makes it so the only way this macro will run is by closing down excel and
restarting it. I wanted to do the same thing without naming specific
workbooks. SO, the macro opens a total of three workbooks:

"Original Name of File being opened"
"Workbook1"
"Workbook2"

So how do I jumb between workbooks and activate them without naming them
specifically then ultimately close them. THANKS!!!!



[email protected]

Closing Workbooks Formula
 
You can store the names in a varible, and then close the workbooks.
After you open them you can store the name.
Bk1= activeworkbook.name

bodhisatvaofboogie ha escrito:

Well I thought about using that, BUT, that would close down everything else.
So just for a hypothetical situation:

person A is working in Excel. Person A wishes to run this macro and not
bother with closing down current work. -- This is not possible due to the
current limitations of the macro. If I were to make the changes in it so all
other workbooks would close then the stuff person A didn't want closed would
be shut down anyway. SO, how do I just shut down the ones I want? How about
this?

Is there a way to change the name of the workbook with a code, because if I
could do that, then I would just plug that into the macro at all appropriate
spots, then when it comes time to close down the extras, I can input the
names that I have them changed to. So how do I change the names of the
workbook with a code?

THANKS!!!

" wrote:

You can use this code at the end of the macro

For Each w In Workbooks
If w.Name < ThisWorkbook.Name Then
w.Close savechanges:=True
End If
Next w

I hope this helps.
Regards

bodhisatvaofboogie ha escrito:

Windows("Book1").Close savechanges:=False
Windows("Book2").Activate
Cells.Select
Selection.Cut
Windows("Book2").ActivateNext
Range("A1").Select
ActiveSheet.Paste
Windows("Book2").Close savechanges:=False

This is the formula I am using to close my extra workbooks. Is there a way
I can do this without the specific ("Book2") or ("Book1")??? Because that
makes it so the only way this macro will run is by closing down excel and
restarting it. I wanted to do the same thing without naming specific
workbooks. SO, the macro opens a total of three workbooks:

"Original Name of File being opened"
"Workbook1"
"Workbook2"

So how do I jumb between workbooks and activate them without naming them
specifically then ultimately close them. THANKS!!!!





NickHK

Closing Workbooks Formula
 
So you want to close all workbooks, except the ones you don't want to close
??
For Each WB In Application.Workbooks.
If MsgBox("Close " & WB.Name & " ?","Confirm",vbYesNo)=vbYes Then
WB.Close True
Next

NickHK

"bodhisatvaofboogie" wrote in
message ...
Well I thought about using that, BUT, that would close down everything

else.
So just for a hypothetical situation:

person A is working in Excel. Person A wishes to run this macro and not
bother with closing down current work. -- This is not possible due to

the
current limitations of the macro. If I were to make the changes in it so

all
other workbooks would close then the stuff person A didn't want closed

would
be shut down anyway. SO, how do I just shut down the ones I want? How

about
this?

Is there a way to change the name of the workbook with a code, because if

I
could do that, then I would just plug that into the macro at all

appropriate
spots, then when it comes time to close down the extras, I can input the
names that I have them changed to. So how do I change the names of the
workbook with a code?

THANKS!!!

" wrote:

You can use this code at the end of the macro

For Each w In Workbooks
If w.Name < ThisWorkbook.Name Then
w.Close savechanges:=True
End If
Next w

I hope this helps.
Regards

bodhisatvaofboogie ha escrito:

Windows("Book1").Close savechanges:=False
Windows("Book2").Activate
Cells.Select
Selection.Cut
Windows("Book2").ActivateNext
Range("A1").Select
ActiveSheet.Paste
Windows("Book2").Close savechanges:=False

This is the formula I am using to close my extra workbooks. Is there

a way
I can do this without the specific ("Book2") or ("Book1")??? Because

that
makes it so the only way this macro will run is by closing down excel

and
restarting it. I wanted to do the same thing without naming specific
workbooks. SO, the macro opens a total of three workbooks:

"Original Name of File being opened"
"Workbook1"
"Workbook2"

So how do I jumb between workbooks and activate them without naming

them
specifically then ultimately close them. THANKS!!!!







All times are GMT +1. The time now is 03:40 AM.

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