Print then close all of excel

sevenfive85

New Member
Joined
Jul 21, 2021
Messages
22
Office Version
  1. 365
Platform
  1. Windows
Hi All,
I have some codes that is not doing as I intend it to, please help. I am using some codes to open a file and transfer information from one workbook to another then print and close all workbook without saving. Everything work fine except the part when it print. If I have "ActiveSheet.PrintOut" it would print the sheet and close the first workbook but not the second workbook without asking if I want to save(which I do not want), however if I remove that " ActiveSheet.PrintOut" it would obviously not print but all workbook would close. The snippet below is the code I currently have. Can someone tell me what code is needed to print the active sheet and close all of excel without saving?




ActiveSheet.PrintOut

ActiveWorkbook.Saved = True
Application.Quit
End Sub
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Hello,

Save all open workbooks first and then Quit

Sub SaveAll()
Dim wb As Workbook
For Each wb In Application.Workbooks
If Not wb.ReadOnly And Windows(wb.Name).Visible Then
wb.Save
End If
Next
End Sub

You could write:-

Sub YourSub()
ActiveSheet.PrintOut
call SaveAll
Application.Quit
End Sub

Jamie
 
Upvote 0
Hi Jamie,
Thank you for the reply. I don't want to save the files, I want it to print then close all workbook/excel without it prompting me to save.
 
Upvote 0
Hello,

VBA Code:
Sub SaveAll()
Dim wb As Workbook
For Each wb In Application.Workbooks
If Not wb.ReadOnly And Windows(wb.Name).Visible Then
wb.Saved = True 'That should do it for you 
End If
Next
End Sub

Jamie
 
Upvote 0
Solution

Forum statistics

Threads
1,214,650
Messages
6,120,734
Members
448,987
Latest member
marion_davis

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