Vai al contenuto principale

Come rinominare tutti i nomi delle immagini in una cartella in base a un elenco di celle in Excel?

Hai mai provato a rinominare le immagini in base a un elenco di celle nel foglio? Se è così, hai qualche trucco per gestire rapidamente il lavoro senza rinominarli uno per uno? In questo articolo, introduco due codici VBA per gestire rapidamente questo lavoro in Excel.

Rinomina tutti i nomi delle immagini in una cartella


Rinomina tutti i nomi delle immagini in una cartella

Per rinominare tutti i nomi delle immagini in una cartella specificata, devi prima elencare i nomi originali nel foglio.

1. Stampa Alt + F11 tasti per abilitare il Microsoft Visual Basic, Applications Edition finestra.

2. Clic inserire > Moduli e incolla il codice sottostante nello script.

VBA: ottieni i nomi delle immagini di una cartella

Sub PictureNametoExcel()
'UpdatebyExtendoffice201709027
    Dim I As Long
    Dim xRg As Range
    Dim xAddress As String
    Dim xFileName As String
    Dim xFileDlg As FileDialog
    Dim xFileDlgItem As Variant
    On Error Resume Next
    xAddress = ActiveWindow.RangeSelection.Address
    Set xRg = Application.InputBox("Select a cell to place name list:", "KuTools For Excel", xAddress, , , , , 8)
    If xRg Is Nothing Then Exit Sub
    Application.ScreenUpdating = False
    Set xRg = xRg(1)
    xRg.Value = "Picture Name"
    With xRg.Font
    .Name = "Arial"
    .FontStyle = "Bold"
    .Size = 10
    End With
    xRg.EntireColumn.AutoFit
    Set xFileDlg = Application.FileDialog(msoFileDialogFolderPicker)
    I = 1
    If xFileDlg.Show = -1 Then
        xFileDlgItem = xFileDlg.SelectedItems.Item(1)
        xFileName = Dir(xFileDlgItem & "\")
        Do While xFileName <> ""
            If InStr(1, xFileName, ".jpg") + InStr(1, xFileName, ".png") + InStr(1, xFileName, ".img") + InStr(1, xFileName, ".gif") + InStr(1, xFileName, ".ioc") + InStr(1, xFileName, ".bmp") > 0 Then
                xRg.Offset(I).Value = xFileDlgItem & "\" & xFileName
                I = I + 1
            End If
            xFileName = Dir
        Loop
    End If
    Application.ScreenUpdating = True
End Sub

3. Stampa F5 per eseguire il codice e viene visualizzata una finestra di dialogo per ricordare di selezionare una cella per visualizzare l'elenco dei nomi. Vedi screenshot:
doc rinominare l'immagine in una cartella 1

4. Clic OK e per selezionare la cartella specificata di cui è necessario elencare i nomi delle immagini nel foglio di lavoro corrente. Vedi screenshot:
doc rinominare l'immagine in una cartella 2

5. Clic OK. I nomi delle immagini sono stati elencati nel foglio attivo.

Quindi puoi rinominare le immagini.

1. Stampa Alt + F11 tasti per abilitare il Microsoft Visual Basic, Applications Edition finestra.

2. Clic inserire > Moduli e incolla il codice sottostante nello script.

VBA: ottieni Rinomina immagini

Sub RenameFile()
'UpdatebyExtendoffice20170927
    Dim I As Long
    Dim xLastRow As Long
    Dim xAddress As String
    Dim xRgS, xRgD As Range
    Dim xNumLeft, xNumRight As Long
    Dim xOldName, xNewName As String
    On Error Resume Next
    xAddress = ActiveWindow.RangeSelection.Address
    Set xRgS = Application.InputBox("Select Original Names(Single Column):", "KuTools For Excel", xAddress, , , , , 8)
    If xRgS Is Nothing Then Exit Sub
    Set xRgD = Application.InputBox("Select New Names(Single Column):", "KuTools For Excel", , , , , , 8)
    If xRgD Is Nothing Then Exit Sub
    Application.ScreenUpdating = False
    xLastRow = xRgS.Rows.Count
    Set xRgS = xRgS(1)
    Set xRgD = xRgD(1)
    For I = 1 To xLastRow
        xOldName = xRgS.Offset(I - 1).Value
        xNumLeft = InStrRev(xOldName, "\")
        xNumRight = InStrRev(xOldName, ".")
        xNewName = xRgD.Offset(I - 1).Value
        If xNewName <> "" Then
            xNewName = Left(xOldName, xNumLeft) & xNewName & Mid(xOldName, xNumRight)
            Name xOldName As xNewName
        End If
    Next
    MsgBox "Congratulations! You have successfully renamed all the files", vbInformation, "KuTools For Excel"
    Application.ScreenUpdating = True
End Sub

3. Stampa F5 per eseguire il codice e viene visualizzata una finestra di dialogo per ricordare di selezionare i nomi delle immagini originali che si desidera sostituire. Vedi screenshot:
doc rinominare l'immagine in una cartella 3

4. Clic OKe seleziona i nuovi nomi che desideri sostituire con i nomi delle immagini nella seconda finestra di dialogo. Vedi screenshot:
doc rinominare l'immagine in una cartella 4

5. Clic OK, viene visualizzata una finestra di dialogo per ricordare che i nomi delle immagini sono stati sostituiti correttamente.
doc rinominare l'immagine in una cartella 5

6. Fare clic su OK e i nomi delle immagini sono stati sostituiti dalle celle nel foglio.

doc rinominare l'immagine in una cartella 6
doc freccia giù
doc rinominare l'immagine in una cartella 7

Articoli relativi:

I migliori strumenti per la produttività in ufficio

🤖 Assistente AI di Kutools: Rivoluziona l'analisi dei dati basandosi su: Esecuzione intelligente   |  Genera codice  |  Crea formule personalizzate  |  Analizzare i dati e generare grafici  |  Richiama le funzioni di Kutools...
Funzioni popolari: Trova, evidenzia o identifica i duplicati   |  Elimina righe vuote   |  Combina colonne o celle senza perdere dati   |   Round senza formula ...
Super ricerca: VLookup a criteri multipli    VLookup a valori multipli  |   VLookup su più fogli   |   Ricerca fuzzy ....
Elenco a discesa avanzato: Crea rapidamente un elenco a discesa   |  Elenco a discesa dipendente   |  Elenco a discesa a selezione multipla ....
Gestore di colonna: Aggiungi un numero specifico di colonne  |  Sposta colonne  |  Attiva/disattiva lo stato di visibilità delle colonne nascoste  |  Confronta intervalli e colonne ...
Funzionalità in primo piano: Messa a fuoco della griglia   |  Vista di progettazione   |   Grande barra delle formule    Gestore di cartelle di lavoro e fogli   |  Resource Library (Testo automatico)   |  Date picker   |  Combina fogli di lavoro   |  Crittografa/decrittografa le celle    Invia e-mail per elenco   |  Super filtro   |   Filtro speciale (filtro grassetto/corsivo/barrato...) ...
I 15 migliori set di strumenti12 Testo Strumenti (aggiungi testo, Rimuovi personaggi, ...)   |   50+ Grafico Tipi (Diagramma di Gantt, ...)   |   40+ Pratico Formule (Calcola l'età in base al compleanno, ...)   |   19 Inserimento Strumenti (Inserisci il codice QR, Inserisci immagine dal percorso, ...)   |   12 Conversione Strumenti (Numeri in parole, Conversione di valuta, ...)   |   7 Unisci e dividi Strumenti (Combina righe avanzate, Celle divise, ...)   |   ... e altro ancora

Potenzia le tue competenze di Excel con Kutools per Excel e sperimenta l'efficienza come mai prima d'ora. Kutools per Excel offre oltre 300 funzionalità avanzate per aumentare la produttività e risparmiare tempo.  Fai clic qui per ottenere la funzionalità di cui hai più bisogno...

Descrizione


Office Tab porta l'interfaccia a schede in Office e semplifica notevolmente il tuo lavoro

  • Abilita la modifica e la lettura a schede in Word, Excel, PowerPoint, Publisher, Access, Visio e Project.
  • Apri e crea più documenti in nuove schede della stessa finestra, piuttosto che in nuove finestre.
  • Aumenta la produttività del 50% e riduce ogni giorno centinaia di clic del mouse!
Comments (8)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hi, I ran the code but the original names are not listing in excel. Only 'Picture Name' comes as the header but no data.
This comment was minimized by the moderator on the site
Thanks for the tip...it was of great help!!
This comment was minimized by the moderator on the site
It doesn't ask me the location of the files, so the script runs in vain and my files aren't being renamed
This comment was minimized by the moderator on the site
СПАСИБО БОЛЬШОЕ! Объединяю два каталога товаров в одни для выгрузки в админку. Все картинки должны быть переименованы в соответствии с ID товара.
Вы сэкономили мне кучу времени и нервов. Спасибо :) Сайт обязательно в закладки.
This comment was minimized by the moderator on the site
Hi, It renames only the first 10 pics of the folder, could you please help me out with the changes for 100 pics. Thanks & Regards
This comment was minimized by the moderator on the site
Hi, edvin.I G Lazar, I have tested the code, it can rename all pictures you list, if it only rename first 10 of the folder, please check what is the picture type, the suffix, in the first code, it just supports to list the pictures(".jpg" ".png" ".img" ".gif" ".ioc" ".bmp"), if your picture is not in the types the code list you can manually add it to the code, like+ InStr(1, xFileName, ".png")
This comment was minimized by the moderator on the site
Hi, i've tried using this however running the 'PictureNametoExcel' macro only returns the first photo file path name. The other photos in the folder wont be listed. Any help would be greatly appreciated.

Side note: I've tested the 'RenameFile' Macro and that works perfectly

Thanks
Sam
This comment was minimized by the moderator on the site
Hi Sam, Select the cell range. I guess this is as a result of you selecting just one cell
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations