Results 1 to 4 of 4

Batch converting XLSX to CSV - I want to retain leading zeros

Threaded View

  1. #1
    Registered User
    Join Date
    09-04-2020
    Location
    England
    MS-Off Ver
    2007
    Posts
    3

    Batch converting XLSX to CSV - I want to retain leading zeros

    Hello everyone,

    Very new to the forum - I have a specific issue with a piece of "off-the-shelf" code, in that I need to retain zeros when batch converting XLSX to CSV. The problem is that I have dates and times in the XLSX files that need to have their first 0 kept (e.g. 00:10 becomes 0:10).

    This is my code currently:

    Sub WorkbooksSaveAsCsvToFolder()
    'UpdatebyExtendoffice20181031
    Dim xObjWB As Workbook
    Dim xObjWS As Worksheet
    Dim xStrEFPath As String
    Dim xStrEFFile As String
    Dim xObjFD As FileDialog
    Dim xObjSFD As FileDialog
    Dim xStrSPath As String
    Dim xStrCSVFName As String
     
        Application.ScreenUpdating = False
        Application.EnableEvents = False
        Application.Calculation = xlCalculationManual
        On Error Resume Next
    Set xObjFD = Application.FileDialog(msoFileDialogFolderPicker)
        xObjFD.AllowMultiSelect = False
        xObjFD.Title = "Batch convert .xlsx to .csv -- Select a folder which contains .XLSX files"
        If xObjFD.Show <> -1 Then Exit Sub
        xStrEFPath = xObjFD.SelectedItems(1) & "\"
     
        Set xObjSFD = Application.FileDialog(msoFileDialogFolderPicker)
     
        xObjSFD.AllowMultiSelect = False
        xObjSFD.Title = "Batch convert .xlsx to .csv -- Select a folder to deposit CSV files"
        
        If xObjSFD.Show <> -1 Then Exit Sub
        xStrSPath = xObjSFD.SelectedItems(1) & "\"
     
        xStrEFFile = Dir(xStrEFPath & "*.xls*")
     
        Do While xStrEFFile <> ""
            Set xObjWB = Workbooks.Open(Filename:=xStrEFPath & xStrEFFile)
            xStrCSVFName = xStrSPath & Left(xStrEFFile, InStr(1, xStrEFFile, ".xlsx") - 1) & ".csv"
            xObjWB.SaveAs Filename:=xStrCSVFName, FileFormat:=xlCSV
            xObjWB.Close savechanges:=False
            xStrEFFile = Dir
      Loop
        Application.Calculation = xlCalculationAutomatic
        Application.EnableEvents = True
        Application.ScreenUpdating = True
    End Sub

    Can anyone help?

    Thanks very much in advance for your time and efforts. x
    Last edited by alansidman; 09-04-2020 at 08:48 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. leading zeros and retain number after rid of decimal
    By laundry in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-24-2017, 05:28 AM
  2. How to retain leading zeros when converting to .csv.
    By Allgermanparts in forum Excel General
    Replies: 2
    Last Post: 03-13-2012, 07:54 AM
  3. Retain Leading Zeros
    By BBretschneider08 in forum Excel General
    Replies: 7
    Last Post: 06-10-2009, 04:41 PM
  4. Concatenate and retain leading, trailing zeros
    By Rick_Stanich in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-13-2009, 11:23 AM
  5. [SOLVED] how to retain leading zeros i.e. 00001 instead of 1
    By Sue in forum Excel General
    Replies: 2
    Last Post: 08-15-2006, 07:20 PM
  6. retain leading zeros when importing
    By LeePotts in forum Excel General
    Replies: 1
    Last Post: 12-05-2005, 03:25 PM
  7. [SOLVED] retain leading zeros in number format
    By Jeff in forum Excel General
    Replies: 5
    Last Post: 02-22-2005, 06:06 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1