Skip to main content

Conas gach ainm íomhá a athainmniú i bhfillteán de réir liosta cealla in Excel?

An ndearna tú iarracht riamh íomhánna a athainmniú de réir liosta cealla i mbileog? Má tá, an bhfuil aon chleas agat an post a láimhseáil go tapa gan iad a athainmniú ceann ar cheann? San Airteagal seo, tugaim isteach dhá chód VBA chun an post seo a láimhseáil go tapa in Excel.

Athainmnigh ainmneacha na n-íomhánna go léir i bhfillteán


Athainmnigh ainmneacha na n-íomhánna go léir i bhfillteán

Chun ainmneacha na n-íomhánna go léir a athainmniú i bhfillteán sonraithe, ní mór duit na hainmneacha bunaidh a liostáil ar an mbileog ar dtús.

1. Brúigh Alt + F11 eochracha chun an Microsoft Visual Basic d’Fheidhmchláir fhuinneog.

2. cliceáil Ionsáigh > Modúil agus greamaigh thíos an cód leis an script.

VBA: Faigh ainmneacha pictiúr de fhillteán

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. Brúigh F5 eochair chun an cód a rith, agus tagann dialóg amach le cur i gcuimhne duit cill a roghnú chun an liosta ainmneacha a aschur. Féach an pictiúr:
athainmnigh doc pictiúr i bhfillteán 1

4. cliceáil OK agus an fillteán sonraithe a roghnú a gcaithfidh tú a liostú sa bhileog oibre reatha. Féach an pictiúr:
athainmnigh doc pictiúr i bhfillteán 2

5. cliceáil OK. Tá ainmneacha na bpictiúr liostaithe ar an mbileog ghníomhach.

Ansin is féidir leat na pictiúir a athainmniú.

1. Brúigh Alt + F11 eochracha chun an Microsoft Visual Basic d’Fheidhmchláir fhuinneog.

2. cliceáil Ionsáigh > Modúil agus greamaigh thíos an cód leis an script.

VBA: Faigh Athainmnigh Pictiúir

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. Brúigh F5 eochair chun an cód a rith, agus tagann dialóg amach le cur i gcuimhne duit na hainmneacha pictiúr bunaidh a theastaíonn uait a athsholáthar a roghnú. Féach an pictiúr:
athainmnigh doc pictiúr i bhfillteán 3

4. cliceáil OK, agus roghnaigh na hainmneacha nua a theastaíonn uait ainmneacha pictiúr a athsholáthar laistigh den dara dialóg. Féach an pictiúr:
athainmnigh doc pictiúr i bhfillteán 4

5. cliceáil OK, tagann dialóg amach le cur i gcuimhne duit gur athraíodh ainmneacha na bpictiúr go rathúil.
athainmnigh doc pictiúr i bhfillteán 5

6. Cliceáil OK agus tá na cealla sa bhileog curtha in ionad ainmneacha na bpictiúr.

athainmnigh doc pictiúr i bhfillteán 6
saighead doc síos
athainmnigh doc pictiúr i bhfillteán 7

Ailt Choibhneasta:

Uirlisí Táirgiúlachta Oifige is Fearr

🤖 Kutools AI Aide: anailís sonraí a réabhlóidiú bunaithe ar: Forghníomhú Chliste   |  Gin Cód  |  Cruthaigh Foirmlí Saincheaptha  |  Anailís a dhéanamh ar Sonraí agus Cairteacha a Ghin  |  Feidhmeanna Kutools a agairt...
Gnéithe Coitianta: Faigh, Aibhsigh nó Aithnigh Dúblaigh   |  Scrios Sraitheanna Bána   |  Comhcheangail Colúin nó Cealla gan Sonraí a Chailleadh   |   Babhta gan Foirmle ...
Cuardaigh Super: Ilchritéir VLookup    VLookup Illuachanna  |   VLookup Trasna Ilbhileoga   |   Amharc doiléir ....
Liosta anuas Casta: Go tapa Cruthaigh Liosta Anuas   |  Liosta anuas Cleithiúnach   |  Liosta Buail Isteach Ilroghnacha ....
Bainisteoir Colún: Cuir Líon Sonrach Colún leis  |  Colúin Bog  |  Scoránaigh Stádas Infheictheachta na gColún Ceilte  |  Déan comparáid idir Raonta & Colúin ...
Gnéithe Réadmhaoin: Fócas Eangaí   |  Amharc Dearaidh   |   Barra Mór na Foirmle    Leabhar Oibre & Bainisteoir Bileog   |  Leabharlann Acmhainní (Uaththéacs)   |  Piocálaí Dáta   |  Comhcheangail Bileoga Oibre   |  Criptigh/Díchriptigh Cealla    Seol Ríomhphost trí Liosta   |  Scagaire Super   |   Scagaire Speisialta (scagaire trom/iodálach/stailc tríd...) ...
Barr 15 Uirlisí12 Téacs uirlisí (Cuir Téacs, Bain Carachtair,...)   |   50 + Cairt cineálacha (Cairt Gantt,...)   |   40+ Praiticiúil Foirmlí (Ríomh aois bunaithe ar lá breithe,...)   |   19 Insertion uirlisí (Cuir isteach Cód QR, Ionsáigh Pictiúr ón gCosán,...)   |   12 Tiontú uirlisí (Uimhreacha le Focail, Comhshó Airgeadra,...)   |   7 Cumaisc & Scoilt uirlisí (Sraitheanna Comhcheangail Casta, Cealla Scoilt,...)   |   ... agus eile

Supercharge Do Scileanna Excel le Kutools le haghaidh Excel, agus Éifeachtúlacht Taithí Cosúil Ná Roimhe. Kutools le haghaidh Excel Tairiscintí Níos mó ná 300 Ardghnéithe chun Táirgiúlacht a Treisiú agus Sábháil Am.  Cliceáil anseo chun an ghné is mó a theastaíonn uait a fháil ...

Tuairisc


Tugann Tab Oifige comhéadan Tabbed chuig Office, agus Déan Do Obair i bhfad Níos Éasca

  • Cumasaigh eagarthóireacht agus léamh tabbed i Word, Excel, PowerPoint, Foilsitheoir, Rochtain, Visio agus Tionscadal.
  • Oscail agus cruthaigh cáipéisí iolracha i gcluaisíní nua den fhuinneog chéanna, seachas i bhfuinneoga nua.
  • Méadaíonn do tháirgiúlacht 50%, agus laghdaíonn sé na céadta cad a tharlaíonn nuair luch duit gach lá!
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