我正在使用excel宏重命名特定文件夹中的文件。如何修复excelvba中的语法错误

我正在使用excel宏重命名特定文件夹中的文件。如何修复excelvba中的语法错误,excel,vba,Excel,Vba,'此方法重命名文件夹中的所有文件名 子重命名AllFileNamesinaFolder() Dim intRowCount为整数 作为整数的Dim intCtr Dim STRFILENAME作为字符串存在 Dim STRFILENAME新建为字符串 作为字符串的Dim strFolder 'Set the folder path strFolder = "C:\Users\rchandramohan\" With Sheet1 'Find the total r

'此方法重命名文件夹中的所有文件名 子重命名AllFileNamesinaFolder() Dim intRowCount为整数 作为整数的Dim intCtr Dim STRFILENAME作为字符串存在 Dim STRFILENAME新建为字符串 作为字符串的Dim strFolder

'Set the folder path
strFolder = "C:\Users\rchandramohan\"
 
With Sheet1
    'Find the total rows count in the sheet
    'This will be the last non-blank cell in column A...
    intRowCount = .Cells(.Rows.Count, "A").End(xlUp).Row
     
    'Loop through from the 2nd row (1st row is Heading)
    'till the total rows in the sheet
    For intCtr = 2 To intRowCount
        'Get the existing filename from the cell
        strFileNameExisting = .Range("A" & intCtr)

        'Get the new filename from the cell
        strFileNameNew = .Range("B" & intCtr)
         
        'Rename the file
      ** Name strFolder & strFileNameExisting As strFolder & strFileNameNew **
    Next intCtr
End With
 
'Display an appropriate message, once complete
MsgBox "All files renamed successfully!", _
                    vbInformation, "All files renamed"
端接头

您好,我需要帮助,我正在使用上述代码重命名文件夹中的文件,我在特定行前后标记**的行中遇到语法错误, 名称strFolder和strFileNameExisting为strFolder和strFileNameNew

我是这个宏的新手,我找不出错误在哪里。请寻找解决方案


该代码在Windows中运行良好。如果您使用的是Mac,这可能就是它产生错误的原因。

在行上放置一个断点,运行函数,并检查strFolder、strFileNameExisting、strFolder和strFileNameNew的值。您会遇到哪种语法错误?对我来说,代码编译时没有任何sytnax错误。您是否加载了任何覆盖
名称的库?
?我收到一个错误窗口,该窗口显示“调试”和其他按钮未找到文件。当我点击“调试”按钮时,它会以黄色显示特定的行。我没有任何库覆盖您得到的确切错误消息是什么?
strfilenamew
是有效的Windows文件名吗?它说的是“找不到文件”,是的,strfilenamew是有效的文件名我也在使用Windows。我需要一点澄清。上面的代码也重命名了它的所有子文件夹。