Vba code does not recognize Georgian Language...

vaxo
4StarLounger
Posts: 432
Joined: 23 Mar 2017, 19:51

Vba code does not recognize Georgian Language...

Post by vaxo »

Hello Friends,

I have Vba code which renames all files in a folder, but when file is in Georgian or other language except English. It does nothing could you help to solve this issue?
This code is this:

Code: Select all

Sub RenameFiles()
Dim xDir As String
Dim xFile As String
Dim xRow As Long
With Application.FileDialog(msoFileDialogFolderPicker)
    .AllowMultiSelect = False
If .Show = -1 Then
    xDir = .SelectedItems(1)
    xFile = Dir(xDir & Application.PathSeparator & "*")
    Do Until xFile = ""
        xRow = 0
        On Error Resume Next
        xRow = Application.Match(xFile, Range("A:A"), 0)
        If xRow > 0 Then
            Name xDir & Application.PathSeparator & xFile As _
            xDir & Application.PathSeparator & Cells(xRow, "B").Value
        End If
        xFile = Dir
    Loop
End If
End With
End Sub

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Vba code does not recognize Georgian Language...

Post by HansV »

Does this work better?

Code: Select all

Sub RenameFiles()
    Dim xDir As String
    Dim objFSO As Object
    Dim objFld As Object
    Dim objFil As Object
    Dim xFile As String
    Dim xRow As Long
    With Application.FileDialog(msoFileDialogFolderPicker)
        If .Show Then
            xDir = .SelectedItems(1)
            Set objFSO = CreateObject(Class:="Scripting.FileSystemObject")
            Set objFld = objFSO.GetFolder(xDir)
            For Each objFil In objFld.Files
                xFile = objFil.Name
                xRow = 0
                On Error Resume Next
                xRow = Application.Match(xFile, Range("A:A"), 0)
                If xRow > 0 Then
                    objFSO.MoveFile xDir & Application.PathSeparator & xFile, _
                    xDir & Application.PathSeparator & Cells(xRow, "B").Value
                End If
            Next objFil
        End If
    End With
End Sub
Warning: this is for Windows only, not for MacOS.
Best wishes,
Hans

vaxo
4StarLounger
Posts: 432
Joined: 23 Mar 2017, 19:51

Re: Vba code does not recognize Georgian Language...

Post by vaxo »

O yes it works, Thanks you are a genius. Problem solved!!

vaxo
4StarLounger
Posts: 432
Joined: 23 Mar 2017, 19:51

Re: Vba code does not recognize Georgian Language...

Post by vaxo »

What was the trick?

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Vba code does not recognize Georgian Language...

Post by HansV »

Dir is a very "old" VBA function; it doesn't work well with Unicode characters in file and folder names.
FileSystemObject is newer, and it does support Unicode.
Best wishes,
Hans

vaxo
4StarLounger
Posts: 432
Joined: 23 Mar 2017, 19:51

Re: Vba code does not recognize Georgian Language...

Post by vaxo »

When thi file name is for example IMG_0003.pdf in folder it give run time error "52" why?

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Vba code does not recognize Georgian Language...

Post by HansV »

I'm sorry, I can't explain that.
Best wishes,
Hans