I am using the following code to email word document (its actually a form) as attachment and to save it to my “P:/” drive. It seems working but the code will need to modify for the following reasons:
1) Once I am done filling out the form and hit the command button to run the macro… the document (form) actually sent to email and also saved to my “P:/” drive successfully but its over saved the master file. I need the form to be blank at all time.
2) Also, I want to have the files to be stamp with date and time (as a file name for the form) that going to be email and save to “p:/” drive.
I will appreciate any help. Thanks!!
The code is:
Private Sub CommandButton1_Click()
Dim OL As Object
Dim EmailItem As Object
Dim Doc As Document
Application.ScreenUpdating = False
Set OL = CreateObject("Outlook.Application")
Set EmailItem = OL.CreateItem(olMailItem)
Set Doc = ActiveDocument
Doc.SaveAs
With EmailItem
.Subject = "Insert Subject Here"
.Body = "Insert message here" & vbCrLf & _
"Line 2" & vbCrLf & _
"Line 3"
.To = "name@company.com"
.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
Flag = True
sPath = "P:\"
ActiveDocument.SaveAs FileName:=sPath & ActiveDocument.Name
Flag = False
Application.Documents.Close
CommandButton1.Visible = False
End Sub
1) Once I am done filling out the form and hit the command button to run the macro… the document (form) actually sent to email and also saved to my “P:/” drive successfully but its over saved the master file. I need the form to be blank at all time.
2) Also, I want to have the files to be stamp with date and time (as a file name for the form) that going to be email and save to “p:/” drive.
I will appreciate any help. Thanks!!
The code is:
Private Sub CommandButton1_Click()
Dim OL As Object
Dim EmailItem As Object
Dim Doc As Document
Application.ScreenUpdating = False
Set OL = CreateObject("Outlook.Application")
Set EmailItem = OL.CreateItem(olMailItem)
Set Doc = ActiveDocument
Doc.SaveAs
With EmailItem
.Subject = "Insert Subject Here"
.Body = "Insert message here" & vbCrLf & _
"Line 2" & vbCrLf & _
"Line 3"
.To = "name@company.com"
.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
Flag = True
sPath = "P:\"
ActiveDocument.SaveAs FileName:=sPath & ActiveDocument.Name
Flag = False
Application.Documents.Close
CommandButton1.Visible = False
End Sub