auto print and close

kemperohlmeyer

Board Regular
Joined
Oct 4, 2006
Messages
73
Do anyone have some code that will automatically print and close a spreadsheet when it is opened?

background: we are performing a data integration on our database. Part of our program is able to open external documents and programs. We want to have our prog point to an excel file, open it (that's the part we can do) and then, once opened (and without external prompting), prints and closes the spreadsheet.

Any code would be great--especially regarding how the macro could automatically run. Thanks.

ko
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
You can put a macro in the Workbook_Open event which will automatically run when the file is opened. Note that depending on your security settings, it may prompt you to enable the macros first, though.

Place this is the ThisWorkbook module of the workbook in the VB Editor:
Code:
Private Sub Workbook_Open()
    ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
    ActiveWorkbook.Close
End Sub
This is Workbook_Open event is known as an Event Procedure, which is VBA code that is automatically triggered by some event. For more on Event Procedures, check out: http://www.cpearson.com/excel/events.htm
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,916
Members
449,093
Latest member
dbomb1414

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