I try to write a function in Visual Basic to create the filename of a spreadsheet based on values in some cells. I am here.
So far I am using this code:
public sub SaveAsA1 () ThisFile = "RWO_" + format (now () ("(", "yyyymmdd") " "Value +" _ "+ range (" D8 ") + format (now ()," hmm ") +" _ "+ range (" D4 "). Value + "_" + Range ("F5") Value ActiveWorkbook.SaveAs File Name: = This file ending sub This code saves the file for the first time, however, whenever I resave the file, it does not update the new file based on the name Does the value in cells
Do anyone know how can I go about writing a function to do this?
You can try to do this by adding code for first instance . This will save the file normally, but whenever you press the SaveAs button , you expect the name to be changed. This code should be located in the ThisWorkbook module (Workbook Module). Private Sub Workbook (As the predecessor saving workgroup Boolean, cancel as Boolean) If SaveAsUI = true then application. Enabled Events = Incorrect Dump This file is string as string = this file = "RWO_" + format (Now ("," Yyyymmdd) + "_" + format (now (), "hmmm") + "_" + range "D4"). Value + "_" + Range ("F5"). Value + "_" + Range ("D8"). Value and ".xlsm" ActiveWorkbook.SaveAs filename: = This file, File format: = XlFileFormat.xlOpenXMLWorkbookMacroEnabled application.EnabledEvents = TrueCancel = True End if End Sub Please note that I this file is ss To end the time and .xlsm extensions Hkr Also I file format parameters to has been added. SaveAs Method .
No comments:
Post a Comment