我的VBA代码中出现路径/文件访问错误?为什么会这样?

问题描述 投票:0回答:1

我得到了一个

运行时错误'75': 路径/文件访问错误

在我的VBA代码中,我不确定该错误背后的原因。

当我调试代码时,我将此特定行视为错误行:

Name strPath & cell.Value As strPath & cell.Offset(0, 1).Value

完整代码是:

Sub RenameFiles()

    Dim strPath As String
    strPath = "C:\Users\Satish Muppidi\Downloads\"

    Dim srcrng As Range
    Set srcrng = Range("A2", ActiveSheet.Range("A2").End(xlDown))

        For Each cell In srcrng

            Name strPath & cell.Value As strPath & cell.Offset(0, 1).Value

        Next cell

    Range("A1").Select

    End Sub

请帮我更新代码。

vba excel-vba excel
1个回答
0
投票

在尝试重命名之前,不要检查文件是否存在。尝试

 If Dir(strpath & cell.value) = "" then

 else
     Name strPath & cell.Value As strPath & cell.Offset(0, 1).Value 
End if
© www.soinside.com 2019 - 2024. All rights reserved.