Rename the pictures using excel

jcsc83ph

New member
Joined
Jan 19, 2018
Messages
1
Reaction score
0
Points
0
Hi Guys,

I need your help. I'm using mac. I try to figured out for this code for change the old names of picture to new name.

Please find attached the code.
Now when I run this code in excel. The error is appear this code area.
"Dim xFileDlg As FileDialogFileDialog". I need your help guys how to run this in mac.

In window, everything is fine. Only the excel in mac the problem.
 

Attachments

  • code.pdf
    32.5 KB · Views: 13
There are many words rolled into one in the code. The pdf file mostly colours the words differently. Try:
Code:
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, ".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


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
(untested - I think I caught most of them)

If it's a Mac problem, I'm out of ideasbut look over here:
http://www.rondebruin.nl/mac.htm
and:
https://stackoverflow.com/questions/16549427/folder-browser-picker-breaks-when-ported-to-mac
 
Last edited:
Back
Top