Hi guys, I'm trying to write a macro to extract the information I have input into another workbook as I press save. Below is the code currently written and it works great, now I'm trying to finish with this last part. Thanks for any help.
Sub SaveInvWithNewName()
Dim NewFN As String
Dim wb As Workbook
Dim ws As Worksheet
'Copy Invoice to a new workbook
NewFN = "C:\Users\Job\Documents\GrubGut\GrubGut Financials\Invoices\" & Range("F6").Value & ".xlsx"
Set ws = ActiveSheet
Set wb = Workbooks.Add
ws.Copy before:=wb.Sheets(1)
wb.SaveAs NewFN, FileFormat:=51
wb.Close
End Sub
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Cancel = True
With Application
.ScreenUpdating = False
.DisplayAlerts = False
End With
Call SaveInvWithNewName
With Sheets("Invoice")
.Range("F6").Value = Left(.Range("F6").Value, 2) & CLng(Right(.Range("F6").Value, 5)) + 1
.Range("B9:E9").ClearContents
.Range("F5").ClearContents
End With
With Application
.ScreenUpdating = True
.DisplayAlerts = True
End With
End Sub
Private Sub Workbook_Open()
With Sheets("Invoice")
.Range("F6").Value = Left(.Range("F6").Value, 2) & CLng(Right(.Range("F6").Value, 5)) + 1
End With
End Sub
Sub SaveForDeveloper()
Dim str As String
str = Application.GetSaveAsFilename
Application.EnableEvents = False
ThisWorkbook.SaveAs Filename:=str, FileFormat:=52
Application.EnableEvents = True
End Sub
Bookmarks