Excel Macro: Search a folder and Print files from excel list

kalyan46

New Member
Joined
Mar 13, 2017
Messages
21
Office Version
  1. 365
Hello all,
I have a folder that averages 100+ excel files per week that I need to print.
However, I need to be able to print them in order based from a list in Excel (either by file name (column A) or a sequence number (column D) ) not the order they are found in the folder so I don't have to manually sort them each time, any ideas?

appreciate your assistance

The code below works great but prints the entire folder in random order

Code:
Sub PrintAllWorkbooks()
'Step 1:Declare your variables
    Dim MyFiles As String
'Step 2: Specify a target folder/directory
    MyFiles = Dir("[URL="file://\\us108fp00\data\Krshare\QIP"]\\us108fp00\data\Krshare\QIP[/URL] conversions\PrintQIPTempFile\*.xls*")
    Do While MyFiles <> ""
'Step 3: Open Workbooks one by one
    Workbooks.Open "[URL="file://\\us108fp00\data\Krshare\QIP"]\\us108fp00\data\Krshare\QIP[/URL] conversions\PrintQIPTempFile" & MyFiles
    'ActiveWorkbook.Sheets("Sheet1").PrintOut Copies:=1
    
    Dim sht
    Dim ShtName
    ShtName = Array("*Rev*") 'ADD SHEET NAMES HERE NOT TO PRINT
For I = 1 To Worksheets.Count
    For J = 0 To UBound(ShtName)
   If LCase(Worksheets(I).Name) Like LCase(ShtName(J)) Then Count = 1
Next J
    If Count = 0 Then Worksheets(I).PrintOut copies:=1
    Count = 0
Next I
    
    
    
    ActiveWorkbook.Close SaveChanges:=False

'Step 4: Next File in the Directory
    MyFiles = Dir
    Loop
End Sub
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

Forum statistics

Threads
1,214,915
Messages
6,122,214
Members
449,074
Latest member
cancansova

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