I have the following code:
This summarizes the information from the different audit sheet, creates a new file with the summary sheets, saves it, and attaches it to an e-mail. Here's the problem. Currently, it's just saving it as "FinalAudit.xlsx". I would like it to save it as "M/V_______________FinalAudit.xlsx". The blank would be the name of the vessel filling out the form. This is found in cell C1 on the "SUMMARY" tab. Any help would be appreciated. Thank you.
Code:
Sub test()
Dim ws As Worksheet, wsSummary As Worksheet, lRow As Long, bCOPY As Boolean
Set wsSummary = Sheets("Final")
Application.ScreenUpdating = False
For Each ws In Worksheets
With ws
Select Case .Name
Case wsSummary.Name
bCOPY = False
Case Else
bCOPY = True
If lRow = 0 Then
lRow = 1
Else
lRow = wsSummary.UsedRange.Rows.Count + 1
End If
End Select
If bCOPY Then
.UsedRange.Copy
wsSummary.Cells(lRow, "A").PasteSpecial xlPasteAll
End If
End With
Next
Set wsSummary = Nothing
With Sheets("Final")
.Columns("D:D").AutoFilter
.Columns("D:D").AutoFilter Field:=1, Criteria1:="<>UnSat"
.Rows("2:" & .Rows.Count).Delete Shift:=xlUp
.Columns("D:D").AutoFilter Field:=1
End With
Sheets("Final").Select
Range("A1").Select
Selection.ClearContents
Rows("2:2").Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Sheets("Crew Knowledge").Select
Range("A1:G2").Select
Selection.Copy
Sheets("Final").Select
Range("A1").Select
ActiveSheet.Paste
Range("A1:G1").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "Final Audit"
Range("A1:G1").Select
Selection.AutoFilter
Sheets("SUMMARY").Select
Sheets("SUMMARY").Copy
ChDir "H:\"
ActiveWorkbook.SaveAs Filename:="H:\FinalAudit.xlsx", FileFormat:= _
xlOpenXMLWorkbook, CreateBackup:=False
Windows("New 2012 Annual Vessel Audit Form.xlsm").Activate
Sheets("Final").Select
Sheets("Final").Copy After:=Workbooks("FinalAudit.xlsx").Sheets(1)
Sheets("SUMMARY").Select
Application.Dialogs(xlDialogSendMail).Show
Application.ScreenUpdating = True
End Sub