ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Print multiple files withour opening (https://www.excelbanter.com/excel-programming/328407-print-multiple-files-withour-opening.html)

petecjr

Print multiple files withour opening
 
I use the following VBA code to print out all files in a folder in MS Word
instantly in the background without opening the documents. When I tried to
use it in MS Excel I received a message indicating that the Application
object in Excel doesn't support the PrintOut method. Is there a way to do
this in Excel? Thanks for any help.


With Application.FileSearch
..FileName = "*.*"
..LookIn = CurDir
If .Execute(msoFileFindSortbyFileName, _
SortOrder:=msoSortOrderAscending) 0 Then
For I = 1 To .FoundFiles.Count
Application.PrintOut FileName:= .FoundFiles(I)
Next I
End If
End With

Ron de Bruin

Print multiple files withour opening
 
Hi

No, you must open them
Something like this will work

Sub Test()
Dim basebook As Workbook
Dim mybook As Workbook
Dim FNames As String
Dim MyPath As String
MyPath = CurDir
FNames = Dir("*.xls")
If Len(FNames) = 0 Then
MsgBox "No files in the Directory"
ChDrive SaveDriveDir
ChDir SaveDriveDir
Exit Sub
End If

Application.ScreenUpdating = False
Do While FNames < ""
Set mybook = Workbooks.Open(FNames)
mybook.PrintOut
mybook.Close False
FNames = Dir()
Loop
Application.ScreenUpdating = True
End Sub



--
Regards Ron de Bruin
http://www.rondebruin.nl



"petecjr" wrote in message ...
I use the following VBA code to print out all files in a folder in MS Word
instantly in the background without opening the documents. When I tried to
use it in MS Excel I received a message indicating that the Application
object in Excel doesn't support the PrintOut method. Is there a way to do
this in Excel? Thanks for any help.


With Application.FileSearch
.FileName = "*.*"
.LookIn = CurDir
If .Execute(msoFileFindSortbyFileName, _
SortOrder:=msoSortOrderAscending) 0 Then
For I = 1 To .FoundFiles.Count
Application.PrintOut FileName:= .FoundFiles(I)
Next I
End If
End With





All times are GMT +1. The time now is 11:44 AM.

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