I tested it and I'm having some issues
Thanks for the help. I tried your suggestion with the code you provided and I just adjusted some of it to fit my situation. So far nothing is happening. I recorded a macro with a button and forgive me as I am still very new to using Word macros but it now seems that the button follows every single Word document since it appears in the Quick Access part of the Ribbon. So with that being, is there a way to only keep this button specific to the document that I created it for? I don't want users accidentally clicking that button for other documents that do not need that feature.
Here is the code you provided with my adjustments:
Sub SaveAs()
'
' SaveAs Macro
'
'
Dim sName As String, aCC As ContentControl, iSpacePos As Integer
Dim sFilename As String, sNow As String, sPath As String
sPath = "C:\Users\data8\Desktop\TEST FOLDER FOR WORD SAVE AS MACRO"
Set aCC = ActiveDocument.ContentControls("Subject")(1)
sName = Trim(aCC.Range.Text)
iSpacePos = InStr(sName, " ")
If iSpacePos > 0 Then
sName = Mid(sName, iSpacePos) & "," & Left(sName, iSpacePos)
sName = Replace(sName, " ", "")
End If
sNow = Format(Now, "dd-mm-yy_HHMMSS")
sFilename = sName & "_" & sNow & ".docm"
ActiveDocument.SaveAs2 FileName:=sPath & sFilename, FileFormat:=wdFormatXMLDocumentMacroEnabled
End Sub
I'm not sure if I did everything correctly but I used the title "Subject" for the content control that I want the file name to be created with. I of course adjusted the path to that test folder. Those were the only obvious things to me that needed to be filled in. So after I did that, I click the button and nothing happens. Can you help me with this?
Thank you for your time.
|