Formatting Column After Saving as CSV in VBA

Theoutlaw700

New Member
Joined
Jun 8, 2022
Messages
8
Office Version
  1. 365
Platform
  1. Windows
I cannot get this to work. Essentially, after saving my worksheet to a csv I need all cells in range E:E to be formatted "[$-en-US]mm/dd/yy hh:mm AM/PM;@" My code looks as follows:

VBA Code:
Sub SaveAsCSV()



Dim path As String
Dim fname As String


path = "Z:\Job Importing\"
fname = "This Week Schedule"


'Copy the invoice sheet to a new workbook

Sheet2.Copy


'Save the new workbook to a specified folder (This will be Z drive)
With ActiveWorkbook
    .Sheets(1).Name = "Weekly Schedule"
    .SaveAs Filename:=path & fname, FileFormat:=62
End With

    Range("E:E").NumberFormat = "[$-en-US]mm/dd/yy hh:mm AM/PM;@"
    ActiveWorkbook.Save
    ActiveWorkbook.Close
'Close the Workbook

End Sub

An example of what my worksheet looks like this:

TechnicianCustomerCustomer IDJob TypeStart Date
[$-en-US]mm/dd/yy hh:mm AM/PM;@
Assignment typeJob Pool?Description
Test21st Century Healthcare21st CenturyMonthly Calibration
06/21/22 10:29 AM​
1Test
TestAmerican Beverage CorpAmerican BeverageService
06/23/22 11:20 AM​
1Test

Thank you very much ahead of time.
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Try changing the format of the column BEFORE you do the inital "SaveAs".
Then you should be able to get rid of the second "Save" line.

And make sure you open the CSV in a Text Editor (NOT EXCEL) to confirm that the format worked (once you open it in Excel, Excel will automatically change it to the format it wants).
 
Upvote 0
That still didn't work. I essentially want to save to a csv, open the new csv file, format Row E:E, save it and close.
 
Upvote 0

Forum statistics

Threads
1,215,730
Messages
6,126,527
Members
449,316
Latest member
sravya

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top