Make folder and save file based on different cell values.

Daroh

Board Regular
Joined
Aug 19, 2016
Messages
62
Hi all, I want to create a code that creates a new folder on the desktop if not there already. Within the folder, I want to save a multiple reports, the data for these reports are from a table on a sheet called 'C_Report'. The data is pulled from a Sheet2 using index/match formula to match the data on the report. What is the best way to do this? Any help is very much appreciated.
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
VBA Code:
Public Sub Reports()

Dim myPath As String, wholePath As String, filePath As String, firstName() As String
Dim vStats As Variant
Dim currentDate As Date
Dim LastRow As Long, ArrayIndex1 As Long

Application.ScreenUpdating = False

With Sheet1
    
        currentDate = .Range("H3").Value2
        LastRow = .Range("A1:A35").Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
        vStats = .Range("A1:E" & LastRow)
        
        myPath = .Range("k3").Value2
        
        LastRow = .Columns(1).Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
        If LastRow = 1 Then: MsgBox ("No Ppl Selected in database."): Exit Sub
    
        wholePath = myPath & "\" & Replace(currentDate, "/", "-") & " X Reports"
        If Dir(wholePath, vbDirectory) = vbNullString Then MkDir (wholePath)
    

With Sheet2
        For ArrayIndex1 = LBound(vStats) To UBound(vStats)
        .Range("B2").Value2 = "PPL Review - " & Replace(Format(currentDate, "dd/mm/yyyy"), "-", "/")
        .Range("c3").Value2 = vStats(ArrayIndex1, 1)
        .Range("c4").Value2 = vStats(ArrayIndex1, 2)
        .Range("c5").Value2 = vStats(ArrayIndex1, 3)
        .Range("c6").Value2 = vStats(ArrayIndex1, 4)
        .Range("c7").Value2 = vStats(ArrayIndex1, 5)
    
     
        filePath = wholePath & "\" & "CPAP Review - " & vStats(ArrayIndex1, 1) & " " & vStats(ArrayIndex1, 2) '
        firstName = Split(vStats(ArrayIndex1, 1), " ")
     
     'create PDF file
        Sheet2.ExportAsFixedFormat Type:=xlTypePDF, Filename:=filePath, Quality:=xlQualityStandard, _
        IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
    
    Next ArrayIndex1
End With

End With
Application.ScreenUpdating = True

End Sub

This is the solution I used for this.
 
Upvote 0
Solution

Forum statistics

Threads
1,215,223
Messages
6,123,714
Members
449,118
Latest member
MichealRed

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