ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Open, print and close workbook (https://www.excelbanter.com/excel-programming/316441-open-print-close-workbook.html)

despistado[_2_]

Open, print and close workbook
 

I need to open a workbook, print it and close, for example from a .ba
file, but that the user can open the workbook without problem.

I write this:
Private Sub WorkBook_Open()
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Application.Quit
End Sub

But when I execute excel.exe c:\myworkbook the excel ask my if I wan
to activate/desactivate macros.

Somebody same me that the best option is to create a new workbook an
write
Private Sub Auto_Open()
Workbooks.Open Filename:="c:\example.xls"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Application.Quit
End Sub

It's possible to do something like this but "c:\example.xls" will be a
parameter

--
despistad
-----------------------------------------------------------------------
despistado's Profile: http://www.excelforum.com/member.php...fo&userid=1629
View this thread: http://www.excelforum.com/showthread.php?threadid=27729


Nick Hodge

Open, print and close workbook
 
despistado

The macro warning will always be a problem unless you

1) Get a certificate and sign the code with it
2) Drop the macro security to low, this will leave the application
vulnerable to macro attack. (Although in truth, I don't think I've ever said
no to the pop up)
3) Make the workbook and add-in and load it in advance.

You cannot pass parameters to VBA from the command line but have you
considered having the code workbook open all the time with some code using
the OnTime method of the application object. So you have this in Workbook1
which then opens your print workbook, with no code in, prints it and closes
it. Like so...

Sub RunOnTime()
'Run this once and at the next 9am it will run
'the procedure OpenBook2
Application.OnTime "09:00:00", "OpenBook2"
End Sub

Sub OpenBook2()
'This procedure opens the book2.xls file
'Prints it and closes it without saving
'It then loops back to RunOnTime and runs again
'at the next 9am
Dim wb2 As Workbook
Set wb2 = Workbooks.Open("C:\Book1.xls")
wb2.PrintOut
wb2.Close SaveChanges:=False
RunOnTime
End Sub


--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
HIS


"despistado" wrote in message
...

I need to open a workbook, print it and close, for example from a .bat
file, but that the user can open the workbook without problem.

I write this:
Private Sub WorkBook_Open()
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Application.Quit
End Sub

But when I execute excel.exe c:\myworkbook the excel ask my if I want
to activate/desactivate macros.

Somebody same me that the best option is to create a new workbook and
write
Private Sub Auto_Open()
Workbooks.Open Filename:="c:\example.xls"
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Application.Quit
End Sub

It's possible to do something like this but "c:\example.xls" will be an
parameter?


--
despistado
------------------------------------------------------------------------
despistado's Profile:
http://www.excelforum.com/member.php...o&userid=16297
View this thread: http://www.excelforum.com/showthread...hreadid=277299




keepITcool

Open, print and close workbook
 

OP could create a VBS script.
if allowed to run on the system..then he will NOT get "enable macro
warnings"


--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


Nick Hodge wrote :

The macro warning will always be a problem unless you

1) Get a certificate and sign the code with it
2) Drop the macro security to low, this will leave the application
vulnerable to macro attack. (Although in truth, I don't think I've
ever said no to the pop up)
3) Make the workbook and add-in and load it in advance.

You cannot pass parameters to VBA from the command line but have you
considered having the code workbook open all the time with some code
using the OnTime method of the application object. So you have this
in Workbook1 which then opens your print workbook, with no code in,
prints it and closes it. Like so...



All times are GMT +1. The time now is 02:08 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com