View Single Post
 
Old 03-01-2018, 10:29 PM
niho niho is offline Windows 10 Office 2016
Novice
 
Join Date: Feb 2018
Posts: 1
niho is on a distinguished road
Default use a Drop-down List Value to determine the file name to save

I have a Word form for users to fill save and mail as an attachment. I have a drop down field to select the Display Name (company name) and it has a corresponding Value (Company Code). When I click submit it save the file with the name of a date field, Company Name and User Name. I need to use the Value of selected drop down (Company Code) instead of Display Name (Company Name).

Public Sub commandbutton1_click()
Dim OL As Object
Dim EmailItem As Object
Dim Doc As Document

Dim strFN As String
Dim strLN As String
Dim strSD As String
Dim strBU As String

Dim myDateStamp As String

Dim strPath As String
Dim strFilename As String


strPath = Environ("USERPROFILE")


strFN = ActiveDocument.SelectContentControlsByTitle("FName ")(1).Range.Text
strLN = ActiveDocument.SelectContentControlsByTitle("LName ")(1).Range.Text
strSD = ActiveDocument.SelectContentControlsByTitle("SDate ")(1).Range.Text
strBU = ActiveDocument.SelectContentControlsByTitle("CName ")(1).Range.Text

strFilename = strFN & "-" & strLN

myDateStamp = Format(Date, "yyyymmdd")

FilePath = strPath & "\Documents\" & myDateStamp & "-ONB-" & strFilename & ".docm"

ActiveDocument.SaveAs (FilePath)

Application.ScreenUpdating = False
Set OL = CreateObject("Outlook.Application")
Set EmailItem = OL.CreateItem(olMailItem)
Set Doc = ActiveDocument
Doc.Save
With EmailItem
.Subject = "[ONB-" & strBU & "]: " & strFN & " " & strLN & " - " & strSD
.Body = "" & vbCrLf & _
"" & vbCrLf & _
""
.To = "itsupport@abc.com"
.Importance = olImportanceNormal 'Or olImprotanceHigh Or olImprotanceLow
.Attachments.Add Doc.FullName
.Display
MsgBox " ****** Thanks for Submitting the On-Boarding Form ****** "
End With
Application.ScreenUpdating = True
Set Doc = Nothing
Set OL = Nothing
Set EmailItem = Nothing

End Sub
Attached Images
File Type: png ScreenCapture.PNG (5.5 KB, 16 views)
Attached Files
File Type: docm ONB-TEST-Form-I.docm (51.9 KB, 10 views)
Reply With Quote