![]() |
|
|
|
#1
|
||||
|
||||
|
Quote:
This code should get you most of the way there. Code:
Sub SaveMeYeezy()
Dim sName As String, aCC As ContentControl, iSpacePos As Integer
Dim sFilename As String, sNow As String, sPath As String
sPath = "C:\Users\username\Desktop\"
Set aCC = ActiveDocument.ContentControls(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
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
|
#2
|
|||
|
|||
|
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. |
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to save Word file by field name as filename using VBA button? | TribeBuckeyeFan | Word VBA | 4 | 02-02-2017 05:58 AM |
How to save Word file by field name as filename using VBA button?
|
chemtoli | Word VBA | 5 | 01-25-2017 08:06 AM |
| Save and rename attachments from ZIP FILE | AndyDDUK | Outlook | 1 | 03-03-2016 12:32 AM |
Have to rename file every time to save workbook
|
intelli | Excel | 3 | 03-27-2014 11:53 PM |
Rename Document & Save
|
d4okeefe | Word VBA | 4 | 05-23-2013 09:35 AM |