Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-20-2022, 10:09 PM
data808 data808 is offline Drawing Button With VBA To Rename File And Save Windows 10 Drawing Button With VBA To Rename File And Save Office 2019
Novice
Drawing Button With VBA To Rename File And Save
 
Join Date: Oct 2022
Posts: 16
data808 is on a distinguished road
Default 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.
Reply With Quote
Reply



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
Drawing Button With VBA To Rename File And Save 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
Drawing Button With VBA To Rename File And Save Have to rename file every time to save workbook intelli Excel 3 03-27-2014 11:53 PM
Drawing Button With VBA To Rename File And Save Rename Document & Save d4okeefe Word VBA 4 05-23-2013 09:35 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:58 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft