Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 10-16-2022, 08:04 PM
Guessed's Avatar
Guessed Guessed is offline Drawing Button With VBA To Rename File And Save Windows 10 Drawing Button With VBA To Rename File And Save Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,166
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Quote:
"102036" is the current time the file is saved which represents 10:20:36PM
This is not good practice. If you ignore the am/pm part then there are two possible times a day. You should either use the 24hr clock or include am/pm info.

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
Reply With Quote
 



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 08:09 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