I have a couple Macros that I KNOW will overwrite the existing file - I need to rewrite this macro so it won't overwrite the file. I have tried various different solutions, but I can't seem to get them to work within my framework.
Here is the macro I have written so far:
Sub email_workbook()
Dim wb1 As Workbook
Dim TempFilePath As String
Dim TempFileName As String
Dim FileExtStr As String
Dim OutApp As Object
Dim OutMail As Object
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
Set wb1 = ActiveWorkbook
TempFilePath = Environ$("temp") & "\"
TempFileName = Range("H22") & wb1.Name & " " & Format(Now, "dd-mmm-yy h-mm-ss")
FileExtStr = "." & LCase(Right(wb1.Name, Len(wb1.Name) - InStrRev(wb1.Name, ".", , 1)))
wb1.SaveCopyAs TempFilePath & TempFileName & FileExtStr
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.to = "person1@PLACE.COM"
.CC = "MPERSON@PLACE.COM" & " " & "LPERSON@PLACE.COM"
.BCC = ""
.Subject = "SUBJECT" & Range("H22")
.Body = "Please review ETC.ETC."
.Attachments.Add TempFilePath & TempFileName & FileExtStr
.Display
End With
On Error GoTo 0
Dim myFile As String
myFile = ActiveWorkbook.Name
Application.DisplayAlerts = False ' Disregard overwriting message.
ActiveWorkbook.SaveAs Filename:="U:\Public\WAKKA\WAKKAWAKKA - To Review"
Kill TempFilePath & TempFileName & FileExtStr
Set OutMail = Nothing
Set OutApp = Nothing
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
Call SaveFileExcel
End Sub
Sub SaveFileExcel() Dim path As String Dim filename1 As String path = "U:\Public\WAKKA - WAKKAWAKKA" filename1 = Range("W1").Text Application.DisplayAlerts = True 'If Dir("f:ull\path\with\filename.xls") <> "" Then ' Kill "f:ull\path\with\filename.xls" 'End If ActiveWorkbook.SaveAs
Filename:=path & filename1 & ".xlsm", FileFormat:=xlOpenXMLWorkbookMacroEnabled Application.DisplayAlerts = True End Sub