+ Reply to Thread
Results 1 to 7 of 7

convert date format to text in all excel files in a folder

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Pakistan
    MS-Off Ver
    Excel 2013
    Posts
    256

    Unhappy convert date format to text in all excel files in a folder

    Hi All,

    i need a code that open all excel files change the specific cell date format to text format.

    I have 100's of files it is difficult to open each file and convert date to text format.

    Thanks
    Farrukh
    Last edited by farrukh; 04-03-2011 at 11:34 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    09-21-2003
    Location
    British Columbia , Canada
    MS-Off Ver
    03,07,10,13
    Posts
    727

    Re: convert date format to text in all excel files in a folder

    What file extention are you xls files ? What sheets ? What cells ?

  3. #3
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Pakistan
    MS-Off Ver
    Excel 2013
    Posts
    256

    Re: convert date format to text in all excel files in a folder

    Thanks for your reply
    i have a file extention is .xls, Sheet1 only have the data and cell is I13 having the date in all excel files.

    Thanks and Regards
    Farrukh

  4. #4
    Valued Forum Contributor
    Join Date
    09-21-2003
    Location
    British Columbia , Canada
    MS-Off Ver
    03,07,10,13
    Posts
    727

    Re: convert date format to text in all excel files in a folder

    Public Sub UpdateFiles()
        Dim fs, f, f1, fc, s
        Dim Value1 As String
        Dim Value2 As String
        Dim Value3 As String
        
        msg = "Enter Full Path ...including ending slash !"
        Path = Application.InputBox(msg, "Update Files", "c:\example\")
        If Path = False Then Exit Sub
        
        Set fs = CreateObject("Scripting.FileSystemObject")
        Set f = fs.GetFolder(Path)
        Set fc = f.Files
        Col = 0
       
        For Each f1 In fc
        
        'NAME
        FullPath = f1.Path
        'EXTENSION
        FileExtention = fs.GetExtensionName(f1)
        
        If FileExtention = "xls" Then
           Workbooks.Open Filename:=FullPath
            
           If SheetExists("Sheet1") Then
              ActiveWorkbook.Sheets("Sheet1").Activate
              
              ' CHANGE FORMAT HERE
              Range("I13").NumberFormat = "@"
              
           End If
           
           ActiveWorkbook.Close SaveChanges:=True
        
        End If
        
        Next
    End Sub
    
    Private Function SheetExists(sname) As Boolean
    '   Returns TRUE if sheet exists in the active workbook
        Dim x As Object
        On Error Resume Next
        Set x = ActiveWorkbook.Sheets(sname)
        If Err = 0 Then SheetExists = True _
            Else SheetExists = False
    End Function

  5. #5
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Pakistan
    MS-Off Ver
    Excel 2013
    Posts
    256

    Re: convert date format to text in all excel files in a folder

    Thanks a lot the code perfectly works only the problem i have while converting the date to text suppose the date is 01-jan-2009 (dd-mmm-yyyy) it convert it like that 39814, i need to convert the date as it is like 01-jan-2009.

    Thanks
    Farrukh

  6. #6
    Valued Forum Contributor
    Join Date
    09-21-2003
    Location
    British Columbia , Canada
    MS-Off Ver
    03,07,10,13
    Posts
    727

    Re: convert date format to text in all excel files in a folder

    Public Sub demo()
    
       ' CHANGE FORMAT HERE
            With Range("I13")
               .NumberFormat = "@"
               If IsNumeric(.Value) Then
                  .Value = Format(.Value, "dd-mmm-yyyy")
               End If
            End With
            
    End Sub

  7. #7
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Pakistan
    MS-Off Ver
    Excel 2013
    Posts
    256

    Re: convert date format to text in all excel files in a folder

    Dear Nimrod

    Thank you for your kind and nice support thanks alot
    Last edited by farrukh; 03-31-2011 at 01:31 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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