I have a simple form (from a template) in Word 2013 and have a 'Submit' button that will:
1. Gather information from fields in the document, name the document, and saveAs.
2. Email the form to pre-set email addresses.
Multiple people will open a document from the template
Private Sub CommandButton21_Click()
Dim OL As Object
Dim EmailItem As Object
Dim Doc As Document
Dim strTagNum As String, strNTID As String, strDate As String
strTagNum = ActiveDocument.SelectContentControlsByTitle("TagNum")(1).Range.Text
strNTID = ActiveDocument.SelectContentControlsByTitle("NTID")(1).Range.Text
strDate = ActiveDocument.SelectContentControlsByTitle("Date")(1).Range.Text
Dim strFilename As String
strFilename = strTagNum & "_" & strNTID & "_" & Format(strDate, "ddmmyyyy") & ".docx"
StrPath = "V:\OPS\Central\Shared\ARM\ALERT"
Application.ScreenUpdating = False
Set OL = CreateObject("Outlook.Application")
Set EmailItem = OL.CreateItem(olMailItem)
Set Doc = ActiveDocument
Doc.SaveAs2 strFilename
With EmailItem
.Subject = "CGF ARM - ALERT ADD/DROP/CHANGE"
.Body = "Please Review this Alert for Continuous Improvement"
.To = "[email protected]"
.Importance = olImportanceNormal
.Attachments.Add Doc.FullName
.Send
End With
Application.ScreenUpdating = True
MsgBox "Alert Record Submitted"
Set Doc = Nothing
Set OL = Nothing
Set EmailItem = Nothing
End Sub
(Credit to Neil Malek at knacktraining.com)
and this topic
Microsoft Word 2013 macro save file name from form content
My questions are:
1. How do I specify the filepath for the saveAs? I have the code in the Macro but the document is being saved in the individual users' Documents folder.
- How to I tell the Macro to pull the username from the form and send it to "username"@example.com?
The rest of the macro works, when the 'Submit' button is pushed, the document is renamed, saved, and sent as an email to pre-set email addresses.
I've updated this from the original question, I was able to answer some of my prevous questions through trial and error.
Thank you for your time.
Doc.SaveAs2 StrPath & "\" & strFilename
. Better to check if folder StrPath exists beforehand. Also consider a few UNC paths instead ofV:
like\\FileServerNAS\Documents\
or\\YourWorkDomain.com\DFSroot\Site\Documents\
. Alternatively, add CustomDocumentProperties to store this path. – PatricK