Salve a tutti,
ho un file Excel che rinomina i file txt della stessa cartella seguendo quanto nella tabella.(Colonna A e B)
| UAE |
AE |
| Bahrain |
BH |
| Swiss |
CH |
| Czech Republic |
CZ |
| Euro |
EU |
| Hungary |
HU |
| India |
IN |
| Kuwait |
KW |
| Qatar |
QA |
| Russia |
RU |
| South Africa |
SA |
| Sweden |
SW |
| U.K. |
UK |
La macro cerca i valori nella colonna A e rinomina il file con il corrispondente della colonna B.
Questa macro funziona sul file che creai tempo fa, ora che ho WIn8 ed Excel 2016 sembra non funzionare...sotto la macro
Mi da errore...
Sub TextFileRenameWithFSOV4()
Dim objFSO As Scripting.FileSystemObject
Dim objFolder As Scripting.Folder
Dim colFiles As Scripting.Files
Dim objfile As Scripting.File
Dim tsFile As Scripting.TextStream
Dim strT As String
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(ThisWorkbook.Path)
Set colFiles = objFolder.Files
For Each objfile In colFiles
If objfile.Name Like "*.txt" Then
Set tsFile = objfile.OpenAsTextStream(ForReading, TristateUseDefault)
TryNextLine:
If tsFile.AtEndOfStream Then GoTo NextFile
strT = tsFile.ReadLine
If InStr(1, LCase(strT), "nomeazienda") > 0 And InStr(1, LCase(strT), "live") > 0 Then
tsFile.Close
'get the code name from the sting
strT = Trim(Mid(strT, InStr(1, LCase(strT), "nomeazienda") + 6, _
InStr(1, LCase(strT), "live") - InStr(1, LCase(strT), "nomeazienda") - 6))
'lookup the new name from a table
strT = Application.VLookup(strT, Worksheets("Extra").Range("A:B"), 2, False)
Name ThisWorkbook.Path & "" & objfile.Name As ThisWorkbook.Path & _
"" & strT & ".txt"
Else
GoTo TryNextLine
End If
End If
NextFile:
Next
End Sub
grazie Mille
Lorenzo