Ok this is what i came up with but i'm getting error message "RUN TIME ERROR 424 - OBJECT REQUIRED" and when i hit debug it highlight this item in my code:
TempFileName = "" & Sourcewb.Name & " " & Format(Now, "dd-mmm-yy h-mm-ss")
Can someone please help me to fix this? Here is my entire code:
Private Sub CommandButton21_Click()
Dim OL As Object
Dim EmailItem As Object
Dim Doc As Document
Dim TempFilePath As String
Dim TempFileName As String
Application.ScreenUpdating = False
Set OL = CreateObject("Outlook.Application")
Set EmailItem = OL.CreateItem(olMailItem)
Set Doc = ActiveDocument
TempFilePath = Environ$("temp") & "\"
TempFileName = "" & Sourcewb.Name & " " & Format(Now, "dd-mmm-yy h-mm-ss")
Doc.SaveAs2 TempFilePath & TempFileName & FileExtStr, FileFormat:=FileFormatNum
With EmailItem
.Subject = "P66 Bayway Refinery Waste Collection Request Form"
.Body = "Please see attached form"
.To = ***@gmail.com
'.cc = ""
'.Importance = olImportanceNormal 'Or olImprotanceHigh Or olImprotanceLow
.Attachments.Add Doc.FullName
.Send
End With
Application.ScreenUpdating = True
Set Doc = Nothing
Set OL = Nothing
Set EmailItem = Nothing
MsgBox "Your form has been emailed. Please check your sent item for a copy"
ThisDocument.Close SaveChanges:=False
End Sub