here is part of the actual procedure, which is much longer.
Public sFolder As String 'This is the path to the individual files
Public sFileMask As String 'This is a unique part of the file name.
Public sFile As String 'The file path and name.
Public sNextReportMonth As String 'Used to create a new folder for the next month report.
Public sReportMonth As String 'The report month which is previous to the 'run' month.
Public sRollup As String 'Name of the target wkbk "Site Safety Metrics Rollup" file
Public imyRow As Integer 'Floating variable used to record a row number
Public oPPTApp As Object
Public oPPTFile As Object
Public oPPTShape As PowerPoint.Shape
Public oPPTSlide As PowerPoint.Slide
Public oTxtRng As TextRange
Public oTmpRng As TextRange
Sub TFP_EHS_Report()
sRollup = ActiveWorkbook.Name 'This is the RollUp target workbook
'There will be a folder for each reporting month which is one month previous to the report 'run' month
'i.e., in August the data is picked up for the July report.
'There will be a folder for each report containing the files related to that report.
'This is the path to the "TFP EHS Report",
sReportMonth = Format(Now() - Day(Now()), "mmm") & " FY" & Format(Now(), "yy")
sFolder = "C:\Monthly Reports\" & sReportMonth & "\TFP EHS Report\"
'These procedures are called
nonserviceMonthlyHours 'Line 63
FlashReport 'Line 126
noservice_Event_Details 'Line 188
FourBlock 'Line 249
SimplexGrinnell 'Line 293
EMEA_AllAccidents 'Line 339
APAC 'Line 407
'All the data has been updated and the workbook is saved.
ActiveWorkbook.Save
'Then the PowerPoint presentations are updated.
TFP_EHS_Presentation
TRS_EHS_Presentation
TSP_EHS_Presentation
'Now the folder for the next month is created.
sNextReportMonth = Format(Now(), "mmm") & " FY" & Format(Now(), "yy")
sNewFolder = "C:\Monthly Reports\" & sNextReportMonth
MkDir sNewFolder
'The folder for the 'TFP EHS Report is created
'The Powerpoint templates will be moved there.
'And the "Site Safety Metrics Rollup" fille will be copied there.
sNewFolder = "C:\Monthly Reports\" & sNextReportMonth & "\TFP EHS Report\"
MkDir sNewFolder
'The PowerPoint templates are moved to the new folder and this will also remove them from the old folder.
Name sFolder & "TFP EHS Metrics Presentation.potx" _
As sNewFolder & "TFP EHS Metrics Presentation.potx"
Name sFolder & "TRS EHS Metrics Presentation.potx" _
As sNewFolder & "TRS EHS Metrics Presentation.potx"
Name sFolder & "TSP EHS Metrics Presentation.potx" _
As sNewFolder & "TSP EHS Metrics Presentation.potx"
'Then the 'Rollup' file is copied to the new folder
'Because of "Run-time Error 70" (Access denied - administration rights) 'SaveAs' is used.
ActiveWorkbook.SaveAs "C:\Monthly Reports\" & sNextReportMonth & "\TFP EHS Report\" & sRollup
MsgBox ("The " & Format(Now() - Day(Now()), "mmm") & " FY" & Format(Now(), "yy") & " Report is complete.")
ActiveWorkbook.Close savechanges:=True
End Sub
'[This is the last presentation and where I was hoping to close the PPT app]
Sub TSP_EHS_Presentation()
'links are updated and text is replaced
With oPPTApp
.ActivePresentation.Save
.ActivePresentation.Close
.Quit
End With
Set oPPTApp = Nothing
End Sub '[returns to above sub]