如何将文件从英语重命名为其他语言?

我真的希望有人能帮助我,因为我需要这样做,

我有一个excel文件,有一些列和一列有英文文件名和其他列有其他语言的文件名。 现在我需要做的是重命名其他语言的文件,是否有可能重命名。

我试过这个代码

Sub pdfrenamefile() Dim oldfile As String Dim nwfile As String Dim rng As Range Dim fname As Range Set rng = Range("Y7", Range("Y" & Rows.Count).End(xlUp)) For Each fname In rng If IsEmpty(fname) Or fname = "" Then 'do nothing Else If FileFolderExists(Cells(1, 1) & fname) Then nwfile = fname.Offset(, 1) & ".PDF" Name Cells(1, 1) & fname As Cells(1, 1) & nwfile fname.Offset(0, 2) = nwfile fname.Offset(0, 3) = "Success" Else Range("AB" & fname.Row) = "File Not Found" End If End If Next fname End Sub 

例如:

示例数据ID OldFileName NewFileName

 1 Sales1.PDF తెలుగు1.PDF 2 Sales02.PDF తెలుగు02.PDF 3 Sales567.PDF తెలుగు567.PDF 4 dest67.PDF తెలుగు67.PDF 

我试过,但它只转换成英文,但不接受其他。

在此先感谢您的帮助。

我已经对您的代码做了最低限度的更改以使其正常工作。 但是,我发现你的代码混淆,所以我还build议进一步的更改。

我必须将您的示例数据放在范围X6:Z10中,以便第一个旧文件名在单元格Y7中。

我必须将文件夹的名称保存在单元格A1中。

我希望我的变化的原因是明确的。 问他们是不是。

 Sub pdfrenamefile() Dim oldfile As String Dim nwfile As String Dim rng As Range Dim fname As Range ' I find your names confusing. For example, You should rename fname to make ' clear that it is a range. You have declared oldname but do now use it. ' You are using methods that require a file system object Dim fso As Object Set fso = CreateObject("Scripting.FileSystemObject") Set rng = Range("Y7", Range("Y" & Rows.Count).End(xlUp)) ' You use too many different methods of located cells. You use ' rng.Offset(0, c), Cells(r, c) and "AB" & r. Will you understand this ' code in six months? What if you decide to change the position of the ' table of names? For Each fname In rng ' fname is a range. fname.Value is its value. If IsEmpty(fname.Value) Or fname.Value = "" Then Else ' I have replaced "FileFolderExist" by "fso.FileExists". ' "Cells(1, 1)" is acceptable but I prefer "Cells(1, 1).Value" ' which makes absolutely clear you want the value. If fso.FileExists(Cells(1, 1).Value & fname.Value) Then ' You already have the extension in the worksheet so ' do not need to add ".PDF". nwfile = fname.Offset(0, 1).Value ' You check the old file exists but not that the new file ' does not exist. I have added another If-Then-Else-End If. If fso.FileExists(Cells(1, 1) & nwfile) Then Range("AB" & fname.Row) = nwfile & " already exists" Else ' The Name statement will not accept non-English letters. ' I have used MoveFile which will accept non-English letters. ' "fname.Value" not "fname" because "fname" is a range. fso.movefile Cells(1, 1).Value & fname.Value, _ Cells(1, 1).Value & nwfile ' You have nwfile in Offset(0,1). Why duplicate it? fname.Offset(0, 2) = nwfile fname.Offset(0, 3) = "Success" End If Else ' I have added the old name to the message to make clear ' what has not been found. Range("AB" & fname.Row) = fname.Value & " not found" End If End If Next fname End Sub