J
johnnykunst
I am creating a filename from form fields using:
Private Sub CommandButton1_Click()
Dim pStr As String
pStr = "C:\Users\John\Desktop\" 'Your directory
pStr = pStr + ActiveDocument.FormFields("nameDD").Result
pStr = pStr + " "
pStr = pStr + ActiveDocument.FormFields("classificationDD").Result
pStr = pStr + " "
pStr = pStr + ActiveDocument.FormFields("wardDD").Result
pStr = pStr + " .docx"
ActiveDocument.SaveAs FileName:=pStr
Dim sCode As String
MsgBox "Your Intelligence report was saved to the central WINTEL inbox for processing & emailing. No further action is required; it is now safe to close the document"
End Sub
However, what i would like to do is for the "nameDD" only use part of the text- we use identification codes for each memeber of staff such as C832, E840, KA345, M65. As you can see, these codes vary in the number of characters. The codes are used to prefix names in the drop down- what I want to do is to extract just the characters from before a "-" (or other mark) so that from "C832- J Wirth" only the "C832" would be extracted, for "M64- S Hunter" only the M64 would be extracted, despite the first example being 4 characters, and the second example being 3 characters.
Help is very much appreciated.
Private Sub CommandButton1_Click()
Dim pStr As String
pStr = "C:\Users\John\Desktop\" 'Your directory
pStr = pStr + ActiveDocument.FormFields("nameDD").Result
pStr = pStr + " "
pStr = pStr + ActiveDocument.FormFields("classificationDD").Result
pStr = pStr + " "
pStr = pStr + ActiveDocument.FormFields("wardDD").Result
pStr = pStr + " .docx"
ActiveDocument.SaveAs FileName:=pStr
Dim sCode As String
MsgBox "Your Intelligence report was saved to the central WINTEL inbox for processing & emailing. No further action is required; it is now safe to close the document"
End Sub
However, what i would like to do is for the "nameDD" only use part of the text- we use identification codes for each memeber of staff such as C832, E840, KA345, M65. As you can see, these codes vary in the number of characters. The codes are used to prefix names in the drop down- what I want to do is to extract just the characters from before a "-" (or other mark) so that from "C832- J Wirth" only the "C832" would be extracted, for "M64- S Hunter" only the M64 would be extracted, despite the first example being 4 characters, and the second example being 3 characters.
Help is very much appreciated.