Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,173
Default 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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default 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...

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I close only 1 workbook when I have many open? jpt consulting Excel Discussion (Misc queries) 3 November 30th 04 11:58 PM
Open, print and close workbook despistado Excel Programming 1 November 11th 04 10:47 AM
Close Open Workbook David Coleman Excel Programming 1 December 30th 03 05:53 PM
Close Open Workbook Bob Umlas[_3_] Excel Programming 1 December 30th 03 05:50 PM


All times are GMT +1. The time now is 05:31 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"