Consulting

Results 1 to 4 of 4

Thread: Solved: Rename Folder - Error 75

  1. #1
    VBAX Regular
    Joined
    Jan 2009
    Posts
    57
    Location

    Solved: Rename Folder - Error 75

    I keep getting error 75 which is Path/File access error if anyone is kind enough to spot what is going wrong for me please. I have checked that the old folder and new folder names are correct.

    Basically I'm changing filenames within the folder first using this code and after the Loop has finished trying to change the folder name:

    [VBA]myPath = ThisWorkbook.Path & "\Handlers\" & hName

    ChDrive myPath

    On Error GoTo changeFilename_error
    ChDir myPath & "\"

    fileName = Dir("*.xlsm")

    Do While fileName <> ""

    'CODE TO CHANGE FILE NAME AND OTHER STUFF

    fileName = Dir()

    Loop

    newFolder = ThisWorkbook.Path & "\Handlers\" & tmp(1) & " " & tmp(2)

    Name myPath as newFolder 'GET ERROR 75 HERE[/VBA]

  2. #2
    VBAX Expert shrivallabha's Avatar
    Joined
    Jan 2010
    Location
    Mumbai
    Posts
    750
    Location
    I do not know the above syntax. However, following should work:
    [VBA]myPath = ThisWorkbook.Path & "\Handlers\" & tmp(1) & " " & tmp(2)
    [/VBA]

    However, this may not work if the folder is not created so you can use following code to create desired folder:
    [VBA]
    Dim FSO As Object
    Set FSO = CreateObject("Scripting.FileSystemObject")
    FSO.CreateFolder (newFolder)
    [/VBA]
    Regards,
    --------------------------------------------------------------------------------------------------------
    Shrivallabha
    --------------------------------------------------------------------------------------------------------
    Using Excel 2016 in Home / 2010 in Office
    --------------------------------------------------------------------------------------------------------

  3. #3
    VBAX Regular
    Joined
    Jan 2009
    Posts
    57
    Location
    Thanks. The folder does exist as it contains the files.

    As I have already accessed the folder to change the file names, Excel is somehow not releasing the folder and assuming that it is in use, hence the error 75.

    I have tried commenting out the file name change code and can get it to work, so need a way to get Excel to release its hold on this folder.

  4. #4
    VBAX Regular
    Joined
    Jan 2009
    Posts
    57
    Location
    OK sorted it.

    Not sure which of these responsible but stuck them both in to make sure.

    ChDrive path
    ChDir path

    Once Excel focused on another folder it worked fine.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •