Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 01-31-2017, 12:16 PM
TribeBuckeyeFan TribeBuckeyeFan is offline How to save Word file by field name as filename using VBA button? Windows 7 32bit How to save Word file by field name as filename using VBA button? Office 2010 32bit
Novice
How to save Word file by field name as filename using VBA button?
 
Join Date: Jan 2017
Posts: 3
TribeBuckeyeFan is on a distinguished road
Default 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
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to save Word file by field name as filename using VBA button? How to save Word file by field name as filename using VBA button? chemtoli Word VBA 5 01-25-2017 08:06 AM
How to save Excel file by field name as filename chemtoli Excel 4 01-22-2017 08:32 AM
How to save Word file by field name as filename using VBA button? How can I save a Word Document as a PDF file with a merged field filename? kp2009 Word VBA 5 08-27-2015 11:45 PM
Save Filename based on Text Field madcar86 Word VBA 8 10-19-2014 12:53 AM
How to save Word file by field name as filename using VBA button? Auto update Filename field Oliver Beirne Word VBA 4 10-19-2012 03:33 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:08 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft