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

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
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,214,653
Messages
6,120,751
Members
448,989
Latest member
mariah3

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