I am trying to write a script that will rename my files using Excel VBA (on a Mac – which I think is important with its file access granting requirement), and getting an “Invalid Procedure Call or Argument Error” when trying to execute the Name function.
I reduced it to this tester code. Can anyone tell me what my problem is?
Sub RenameTester()
Dim folderPath As String
Dim originalFileName As String
Dim newFileName As String
Dim oldFilePath As String
Dim newFilePath As String
Dim AccessGranted As Boolean
folderPath = "/Users/sparky/Desktop/"
originalFileName = "OLD_NAME_1.jpg"
newFileName = "FILE_RENAMED_1.jpg"
oldFilePath = folderPath & originalFileName
newFilePath = folderPath & newFileName
MsgBox "Old: " & oldFilePath & " new: " & newFilePath. 'this all looks correct
If Dir(oldFilePath) <> "" Then ' Checks if the file exists
FileArray = Array(oldFilePath)
AccessGranted = GrantAccessToMultipleFiles(FileArray)
MsgBox AccessGranted 'this returns true
Name oldFilePath As newFilePath 'this is where the error occurs
Else
MsgBox "File not found: " & oldFilePath & ". Check your path and prefix"
End If
I expected it to execute with no errors. I checked it with multiple files and file names and paths. Even though the file exists and the GrantAccesstoMultipleFiles() function returns “True” I still get a pop-up asking me to grant access to the file, and even when I do grant access, I still get an “Invalid Procedure Call” error.
MamaCoder is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.