View Single Post
 
Old 06-10-2019, 11:51 PM
kiwimtnbkr kiwimtnbkr is offline Windows 10 Office 2010 64bit
Advanced Beginner
 
Join Date: Oct 2017
Posts: 69
kiwimtnbkr is on a distinguished road
Default

Got the individual worksheets going bang on and I thought it would also be a case of just transferring the code over to the 'ThisWorkbook' and away I would go to RESOLVED but as we have already discovered, I am not as clever as I would like to think I am...

Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim xFileName As String
Dim L5part As String, H17part As String
        'L5part = ThisWorkbook.Worksheets("Report template - Advanced").Range("L5").Value
        'L5part = Replace(Replace(L5part, " / ", "/"), "/", "_")
        'H17part = ThisWorkbook.Worksheets("Report template - Advanced").Range("H17").Value
        'H17part = Replace(H17part, "/", "_")
        L5part = ThisWorkbook.Worksheets("Report template - NextGen").Range("L5").Value
        L5part = Replace(Replace(L5part, " / ", "/"), "/", "_")
        H17part = ThisWorkbook.Worksheets("Report template - NextGen").Range("H17").Value
        H17part = Replace(H17part, "/", "_")
        'L5part = ThisWorkbook.Worksheets("Report template - All Future").Range("L5").Value
        'L5part = Replace(Replace(L5part, " / ", "/"), "/", "_")
        'H17part = ThisWorkbook.Worksheets("Report template - All Future").Range("H17").Value
        'H17part = Replace(H17part, "/", "_")
If SaveAsUI <> False Then
    Cancel = True
    xFileName = Application.GetSaveAsFilename(H17part & " Report" & Range("A1").Value & L5part, "Excel Macro-Enabled Workbook (*.xlsm), *.xlsm", , "Save report as")
    If xFileName <> "False" Then
      Application.EnableEvents = False
      ActiveWorkbook.SaveAs Filename:=xFileName, FileFormat:=xlOpenXMLWorkbookMacroEnabled
      Application.EnableEvents = True
    End If
End If
End Sub
The Save workbook is now causing the final bit of grief.....If I comment out two of the three worksheets, the Save Workbook routine works - but if they are uncommented then the routine fails to get the H17part and L5part information.

Last edited by kiwimtnbkr; 06-11-2019 at 01:54 AM. Reason: routine failure clarification
Reply With Quote