so i've been looking here and googling for quite a bit, and i can find some good tips on how to code this, but nothing on the how to keep the dateformat.
I want to save a file i've opened in the routine, but with the date in this particular format, 20160127 (as it is in the source-cell) added to the filename.
Right now, the value in Fname gets stored as 01/27/2016, not in its current format.
Fname = [cellwithdate]
Daily.SaveAs ("D:\\Docs\\vba\\Daily Summary_US_ " & Fname & ".xlsx")
Current filename is "Daily Summary_US_.xlsx". Can i just add Fname to it like so? And how do i keep it in its correct format?
cheers.
You can use Format to achieve your goal:
Dim Fname As String
Fname = Format([cellwithdate], "yyyyMMdd")
Daily.SaveAs ("D:\Docs\vba\Daily Summary_US_ " & Fname & ".xlsx")
For getting the current date and time with format:
Format(Now, "yyyyMMdd_hhmmss")
MSDN with the detail explanation https://msdn.microsoft.com/en-us/library/office/gg251755.aspx
For saving the file in SaveAs , it is better to state the file format as:
Daily.SaveAs "D:\Docs\vba\Daily Summary_US_ " & Fname & ".xlsx", xlOpenXMLWorkbook
https://msdn.microsoft.com/en-us/library/office/ff198017.aspx
Or You can use:
Fname = [cellwithdate].Text
to keep the cell's original format (as it is in the source-cell).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.