Macro to print a list of excel files from a folder

Reo94x

New Member
Joined
Apr 24, 2014
Messages
8
I am looking for a macro that i can assign to a master excel sheet that will recognise the **hyperlinked files * already in the file and print a certain sheet with the print area to a printer of my choice. How would i go about doing this? i have tried a number of macros i have seen online but none have worked?

I would also like to create a similar macro that will save all the files to pdf using the 'save as' system that is working on my version of excel. currently to pdf a list of files i have to open each excel go to file 'save as' and it takes to long!

thankyou to anyone that can help :)

Ryan

*note these files have macro's in them so they will be XML rather than XLS right?

** in the master the files in the folder are shown in a list as hyperlinks
 
Last edited:

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
i believe u have code for opening every workbook based on hyperlinks below code us for saving a defined range in pdf in the same path where the workbook is saved and with same workbook name for pdf


Sub Macro1()


'below is the selection
Range("B2:I16").Select

'the below command will save the pdf in its path with the same workbook name
Selection.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
ThisWorkbook.Path & "\" & "activeworkbook.name" & ".pdf", Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
True
End Sub
 
Upvote 0
i believe u have code for opening every workbook based on hyperlinks below code us for saving a defined range in pdf in the same path where the workbook is saved and with same workbook name for pdf


Sub Macro1()


'below is the selection
Range("B2:I16").Select

'the below command will save the pdf in its path with the same workbook name
Selection.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
ThisWorkbook.Path & "\" & "activeworkbook.name" & ".pdf", Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
True
End Sub



sriram,

Thankyou for your response, i tried that and it created a pdf but it created a pdf of the list of excel hyperlinks, what i need is a macro that will actually pdf the files that are in the list
:)

thankyou for trying
 
Upvote 0
hi reo

actually in the list it should contain the file name and path so the excel opens and then does this action... so to save the workbook must be opned
 
Upvote 0
if the list has filepath then the code goes here

workbooks.open(range("a1)".value) 'in bracker it shud contain path and filename

then my code goes here
 
Upvote 0
Sriram,
I tried this and it worked :) thankyou just one last thing its saving it as activeworkbook.name how would i get it to save as the actual file name with .pdf ?
 
Upvote 0
Sriram,

Apologies for this i am a bit of a vba Newbie does this go at the start:
workbooks.open(range("a1)".value)

and what do you mean by path and filename?​
 
Upvote 0
Dear Reo


The code which I gave u earlier will actually save as PDF of a selected range of a current open file .. so to open a file the excel needs its path and file name.. so the list which u have should contain the path and filename.. to get the file path and names please use the below code which will give u the list of all files in folder and even subfolders.

'Force the explicit delcaration of variables
Option Explicit

Sub ListFiles()

Cells.Clear

MsgBox "To avoid error" & vbNewLine & vbNewLine & "1. please make sure to enable microsoft scripting runtime from tools-> reference" & vbNewLine & _
"2. if not available please browse and select scrunn.dll " & vbNewLine & "3. then again enable the microsoft scripting runtime", vbInformation
'please make sure to enable microsoft scripting runtime if not available please browse and select scrunn.dll then enable
'the runtime so to run this code without error

'Set a reference to Microsoft Scripting Runtime by using
'Tools > References in the Visual Basic Editor (Alt+F11)

'Declare the variables
Dim objFSO As Scripting.FileSystemObject
Dim objTopFolder As Scripting.Folder
Dim strTopFolderName As String
Dim strpath2 As String

'Insert the headers for Columns A through F
Range("A1").Value = "File Name"
Range("B1").Value = "File Size"
Range("C1").Value = "File Type"
Range("D1").Value = "Date Created"
Range("E1").Value = "Date Last Accessed"
Range("F1").Value = "Date Last Modified"
Range("G1").Value = "File path"


'this will select the folderpath
With Application.FileDialog(msoFileDialogFolderPicker)
.AllowMultiSelect = False
If .Show <> -1 Then MsgBox "No folder selected! Exiting sub...": Exit Sub
strpath2 = .SelectedItems(1)
End With




'Assign the top folder to a variable
strTopFolderName = strpath2

'Create an instance of the FileSystemObject
Set objFSO = CreateObject("Scripting.FileSystemObject")

'Get the top folder
Set objTopFolder = objFSO.GetFolder(strTopFolderName)

'Call the RecursiveFolder routine
Call RecursiveFolder(objTopFolder, True)

'Change the width of the columns to achieve the best fit
Columns.AutoFit
MsgBox "done"

End Sub

Sub RecursiveFolder(objFolder As Scripting.Folder, _
IncludeSubFolders As Boolean)

'Declare the variables
Dim objFile As Scripting.File
Dim objSubFolder As Scripting.Folder
Dim NextRow As Long

'Find the next available row
NextRow = Cells(Rows.Count, "A").End(xlUp).Row + 1

'Loop through each file in the folder
For Each objFile In objFolder.Files
Cells(NextRow, "A").Value = objFile.Name
Cells(NextRow, "B").Value = objFile.Size
Cells(NextRow, "C").Value = objFile.Type
Cells(NextRow, "D").Value = objFile.DateCreated
Cells(NextRow, "E").Value = objFile.DateLastAccessed
Cells(NextRow, "F").Value = objFile.DateLastModified
Cells(NextRow, "G").Value = objFile.path
NextRow = NextRow + 1
Next objFile

'Loop through files in the subfolders
If IncludeSubFolders Then
For Each objSubFolder In objFolder.SubFolders
Call RecursiveFolder(objSubFolder, True)
Next objSubFolder
End If
End Sub









So after u get the file names and path use my code

Sub Macro1()


Sub test()
Dim path As String
Dim actbook As String
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Sheets("Sheet1").Select ‘rename the sheet that contains the list
Range("f2").Select ‘rename the range the path starts from
Do
path = ActiveCell.Value
Workbooks.Open Filename:=path
actbook = ActiveWorkbook.Name

'below is the selection
Range("B2:I16").Select

'the below command will save the pdf in its path with the same workbook name
Selection.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
ThisWorkbook.Path & "\" & "activeworkbook.name" & ".pdf", Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
True
End Sub
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,120
Members
451,399
Latest member
alchavar

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