VBA: How to correctly format a date string before writing it to a CSV file?
I'm relatively new to this, so bear with me. I've been struggling with this for a few days now and could really use some help. I am trying to export data from an Excel sheet to a CSV file using VBA, but I run into issues with the date formatting. The dates in my Excel sheet are formatted as `MM/DD/YYYY`, but when I write them to the CSV file, they appear as `MM/DD/YY`, which is causing confusion in downstream applications that expect the full year format. I have tried using the `Format` function, but it doesn't seem to affect the output in the CSV. Hereβs a snippet of my code: ```vba Sub ExportToCSV() Dim ws As Worksheet Dim csvFilePath As String Dim lastRow As Long Dim i As Long Set ws = ThisWorkbook.Sheets("Data") csvFilePath = "C:\path\to\your\output.csv" lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row Open csvFilePath For Output As #1 For i = 1 To lastRow Print #1, ws.Cells(i, 1).Value & "," & Format(ws.Cells(i, 2).Value, "MM/DD/YYYY") Next i Close #1 End Sub ``` Iβm not sure if the scenario is with how I'm opening the file or how I'm formatting the date. When I check the CSV after writing, the dates still display incorrectly. Is there a better way to ensure the dates are formatted correctly in the CSV? Any help would be greatly appreciated! For context: I'm using Vba on macOS. What's the best practice here?