I am stuck.
I need to save the file without macros and attach it to an email/
I cannot get any of your examples to work/
If you have another option, I will take it.
I need to save the file without macros and attach it to an email/
I cannot get any of your examples to work/
If you have another option, I will take it.
VBA Code:
Dim OlApp As Object
Set OlApp = CreateObject("Outlook.Application")
Dim NewMail As Object
Set NewMail = OlApp.CreateItem(0)
Dim TempFilePath As String
Dim FileFullPath As String
Dim MyWb As Workbook
Dim TempFileName As String 'A portion of the file is hardcoded below
Dim CName As String 'Replaces initials in the file name
CName = Sheets("Script").Range("K1").Value
Dim xStrDate As String 'Date/time custom format stamp for file
xStrDate = Format(Now, "_hh-mm_yyyymmdd")
Dim xStrDate2 As String 'Date/time custom format stamp for email text
xStrDate2 = Sheets("Script").Range("L1").Value
Dim FileNew As String
Dim CallNums As String 'Number of calls in email text
CallNums = Sheets("Script").Range("J1").Value
Set MyWb = ThisWorkbook
With Application
.ScreenUpdating = False
.EnableEvents = False
.DisplayAlerts = False
End With
'Save your workbook in your temp folder of your system below code gets the full path of the temporary folder
'in your system
TempFilePath = Environ$("temp") & "\"
TempFileName = "Class" & CName & xStrDate
ActiveWorkbook.SaveAs Filename:=TempFilePath & TempFileName & ".xlsx", FileFormat:=51
'Complete path of the file where it is saved
FileFullPath = TempFilePath & FileNew
'Now save your current workbook at the above path
MyWb.SaveAs FileFullPath
With NewMail
.To = "first person"
.CC = "second person"
' .BCC = "third person "
.Subject = "class file " & Date
.Body = "Good morning. Here is my file with " & CallNums & " class from last night's session from " & xStrDate3 & " to " & xStrDate2 & ". " & vbNewLine & vbNewLine_
.Attachments.Add FileFullPath '--- full path of the temp file where it is saved
.Display 'or use .Display to show you the email before sending it.
End With
Last edited by a moderator: