Print XLS files in folder based on name

scotsrule08

New Member
Joined
Jun 21, 2018
Messages
45
Good day Friends!

I have a folder with dozens of spreadsheets that I need to print. I only want to print the files that contain the word "COMPLETE" in the filename.

It would be much preferred to not have to open each file to print as there are a ton.

Thank you!
 
Last edited:

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Use This.
Cange "C:\trabajo" by the name of your folder.

Code:
Option Explicit
'
Declare Function apiShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
    ByVal hwnd As Long, _
    ByVal lpOperation As String, _
    ByVal lpFile As String, _
    ByVal lpParameters As String, _
    ByVal lpDirectory As String, _
    ByVal nShowCmd As Long) _
    As Long
'
Public Sub PrintFile(ByVal strPathAndFilename As String)
 
    Call apiShellExecute(Application.hwnd, "print", strPathAndFilename, vbNullString, vbNullString, 0)
 
End Sub
'
Sub Print_File_Complete()
    Dim ruta As String
    Dim arch
    ruta = "C:\trabajo\"
    arch = Dir(ruta & "*.xlsx")
    Do While arch <> ""
        If InStr(1, UCase(arch), "COMPLETE") > 0 Then
            PrintFile (ruta & arch)
        End If
        arch = Dir()
    Loop
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,189
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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