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
 

Some videos you may like

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
54,816
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
 

Watch MrExcel Video

Forum statistics

Threads
1,111,490
Messages
5,541,028
Members
410,540
Latest member
FlaShow
Top