VBA ? - Print all files in a directory

dipsmom

New Member
Joined
Nov 17, 2002
Messages
40
:rolleyes: I am trying to write a VBA program to select all the files (without listing each file) in a directory and print them . The number of files can vary month to month. In Excel, you can highlight all the files and using the Tool Button, you can click Print and it will print all the files.
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
If your folder assocaitions are setup correctly, you should be able to do this without any VBA.
1. Using explorer just select each file you want to print(Ctrl-A for all files)
2. Right click on the highlighted area.
3. Select print.

This will print out all the files within a folder.(I haven't used this, so I'm not sure exactly what you will get, but it it works it should save you some coding.) If you specifically need code, just post back.
 
Upvote 0
:rolleyes:
This is part of a VBA code I am writing to print out all our Month end reports. This is just a small section of the macro. This section is all of our Expense accounts by Department. There are approximately 100 reports in this directory to be printed.

I am printing these reports manually every month and inserting them into the report packs. All the other reports print automatically every month with a macro button and I am wanting to add these reports to the pack. :oops:
 
Upvote 0
Give this code a try, you will need to update the Path variable.

Private Sub CommandButton1_Click()
Dim wb As Workbook, ws As Worksheet
Dim FileName As String, Path As String
Set wb = ActiveWorkbook
Set ws = ActiveSheet

Path = "C:\test\*.xls"

FileName = Dir(Path, vbNormal)
Do Until FileName = ""
Application.DisplayAlerts = False
Workbooks.Open Left(Path, Len(Path) - 5) & FileName
Set wb = ActiveWorkbook
For Each ws In wb.Worksheets
ws.PrintOut
Next
wb.Close
FileName = Dir()
Loop
End Sub
 
Upvote 0
Missed a piece.
Cbrine said:
Give this code a try, you will need to update the Path variable.

Private Sub CommandButton1_Click()
Dim wb As Workbook, ws As Worksheet
Dim FileName As String, Path As String
Set wb = ActiveWorkbook
Set ws = ActiveSheet

Path = "C:\test\*.xls"

FileName = Dir(Path, vbNormal)
Application.DisplayAlerts = False
Do Until FileName = ""
Workbooks.Open Left(Path, Len(Path) - 5) & FileName
Set wb = ActiveWorkbook
For Each ws In wb.Worksheets
ws.PrintOut
Next
wb.Close

FileName = Dir()
Loop
Application.displayalerts =True
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,540
Messages
6,125,409
Members
449,223
Latest member
Narrian

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
Back
Top