Print out a folder in a network drive
-
-
-
Re: Print out a folder in a network drive
Hi...
Replace C:\Dummy Files with your required folder path...
Code
Display MorePrivate Sub CommandButton1_Click() Dim objFSO As Object Dim objFolder As Object Dim objFile As Object Dim ws1 As Worksheet Dim y As Long Dim x As Long Set objFSO = CreateObject("Scripting.FileSystemObject") Set ws1 = Sheets("Sheet1") y = 2 x = 4 Application.ScreenUpdating = False 'Get the folder object associated with the directory Set objFolder = objFSO.GetFolder("C:\Dummy Files") 'Loop through the Files collection For Each objFile In objFolder.Files ws1.Cells(y, x).Value = objFile.Name y = y + 1 Next LastRow = ws1.Range("D" & Rows.Count).End(xlUp).Row ws1.PageSetup.PrintArea = "D2:D" & LastRow ws1.PageSetup.PaperSize = xlPaperA4 ws1.PageSetup.TopMargin = 72 ws1.PageSetup.CenterHeader = "&""Arial Black,Bold""&20Files in Folder - " & objFolder & Chr(13) Application.ScreenUpdating = True ActiveWindow.SelectedSheets.PrintPreview 'Clean up! Set objFolder = Nothing Set objFile = Nothing Set objFSO = Nothing Application.ScreenUpdating = True End Sub
Participate now!
Don’t have an account yet? Register yourself now and be a part of our community!