VBA Code to Keep File Open

Michael Fowler

New Member
Joined
Jan 23, 2024
Messages
28
Office Version
  1. 2021
  2. 2016
Platform
  1. Windows
I'm successfully using an Excel file with VBA code to send a copy of the Active Sheet as an attachment in an email, and this works very well. But now I have a similar situation except that now I need to send the whole file rather than just one sheet. I've changed this part of the code ...

Set Wb = Application.ActiveWorkbook
ActiveSheet.Copy
Set Wb2 = Application.ActiveWorkbook

to this ...

Set Wb = Application.ActiveWorkbook
ActiveWorkbook.Copy
Set Wb2 = Application.ActiveWorkbook

... and as a result of doing this, the original source Excel file closes after running the macro, whereas it doesn't when I'm only sending one sheet. Please advise what coding I need to insert or modify to keep the original Excel source file remaining open.

Thanks, Michael
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Following on from my initial question, what VBA code do I need to send specific sheets in an email ? (I already have the code to send one sheet.)
 
Upvote 0
" except that now I need to send the whole file rather than just one sheet" & "the original source Excel file closes after running the macro" Seemed like 2 issues that you were interested in. This seems different? If you want to send only some sheets copy the file to a new location, removed the undesired sheets and then e-mail it. Dave
 
Upvote 0

Forum statistics

Threads
1,215,096
Messages
6,123,074
Members
449,093
Latest member
ripvw

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