How to save Word file by field name as filename using VBA button?
I have created a very simple Word form to be used as evaluations within my department. After the evaluator fills in the various check boxes, dates, etc, I have a simple submit button that sends the completed evaluation as an attachment to the Chief of the department. The very first field on the form is the "clinician being reviewed", a fill in text box. I would like for the subject line of the email AND the file name of the document to be that person's name, then the type of evaluation (I have 3 different evals, depending on what is being done). Example: If I am evaluating Charles Xavier, the file name would be Charles Xavier.doc, and the email subject would be Charles Xavier, Treatment Plan. My code is listed below:
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.SaveAs2 FileName:=("M:\File Name.doc")
With EmailItem
.Subject = "Treatment"
.Body = "" & vbCrLf & _
"" & vbCrLf & _
""
.To = "Chief's email"
.Cc = ""
.Importance = 2
.Attachments.Add Doc.FullName
.Send
Doc.Close
End With
Application.ScreenUpdating = True
Set Doc = Nothing
Set OL = Nothing
Set EmailItem = Nothing
End Sub
|