Closing one workbook

Richynero

Board Regular
Joined
Jan 16, 2012
Messages
147
Hi there,

I have a macro that does various things with a pivot table, it then duplicates the file and saves it as something else.

I then need to close this duplicated file once it has been saved but when I use activeworkbook.close it closes the active workbook and the original file. I need the original pivot table still open to continue doing other duplications.

I have tried referencing the new file name and closing that but it still closes both files.

Any help would be greatly appreciated.

Thanks!

Richard
 

Some videos you may like

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

ChrisGrigg

New Member
Joined
Nov 14, 2018
Messages
6
hello any chance you could advise how this was fixed? I need to do the same thing.

thx
 

mrshl9898

Well-known Member
Joined
Feb 6, 2012
Messages
1,414
Something like this:

You want to declare the current book and refer to it when closing

Code:
Sub wbclose()


Dim wb As Workbook


Application.DisplayAlerts = False


Set wb = ThisWorkbook


Sheets("Sheet1").Copy 'creates new, now active book


wb.Close


Application.DisplayAlerts = True


End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,109,009
Messages
5,526,258
Members
409,689
Latest member
martin_br

This Week's Hot Topics

Top