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

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
58,954
Office Version
  1. 365
Platform
  1. Windows
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
 

Forum statistics

Threads
1,141,152
Messages
5,704,594
Members
421,358
Latest member
Redstar13

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
Top