Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #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
  #2  
Old 02-01-2017, 02:22 AM
gmayor's Avatar
gmayor gmayor is offline How to save Word file by field name as filename using VBA button? Windows 10 How to save Word file by field name as filename using VBA button? Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,137
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

What sort of 'text field'? What is the name of the text field?
Can you post the form?
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 02-01-2017, 08:56 AM
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

I'll try to put it up tonight; my work network won't allow me to upload.

Last edited by TribeBuckeyeFan; 02-01-2017 at 11:32 AM.
Reply With Quote
  #4  
Old 02-01-2017, 11:33 AM
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

OK, there we go. Had to send it to myself, then upload from my phone.
Reply With Quote
  #5  
Old 02-02-2017, 05:58 AM
gmayor's Avatar
gmayor gmayor is offline How to save Word file by field name as filename using VBA button? Windows 10 How to save Word file by field name as filename using VBA button? Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,137
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

See the attached, which includes a couple of extra functions from my web site. Change the e-mail address(es) and the body text as required.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
Reply



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 09:33 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