gpt4 book ai didi

vba - 重命名书籍时出现运行时错误 13

转载 作者:行者123 更新时间:2023-12-03 01:36:04 26 4
gpt4 key购买 nike

有 book1,其中一列是旧书的名称,另一列是新书的名称(旧书需要在新书中重命名)。 n,m 个数字。

发生错误:

Run-time error ‘13’ Type mismatch in line

OldName = "" + n + ".xlsm"

代码:

    Sub Кл()

Dim OldName, NewName
Dim book1 As Workbook
Dim t As Long, m As Long, n As Long


Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.EnableEvents = False

Set book1 = Workbooks.Open("E:\Super M\Проект ставки\Поиск решения\Усов
7\вспомогательные программы\Книга в лист\виз.xlsx")
For t = 3 To 5

n = book1.Worksheets("общ").Range("C" & t).Value
m = book1.Worksheets("общ").Range("C" & t).Offset(0, 1).Value

OldName = "" + n + ".xlsm"
NewName = "" + m + ".xlsm"

Name OldName As NewName

OldName = "E:\Super M\Проект ставки\Поиск решения\Усов
7\вспомогательные программы\Книга в лист\Отборные
условия\Откуда\" + n + ".xlsm"
NewName = "E:\Super M\Проект ставки\Поиск решения\Усов
7\вспомогательные программы\Книга в лист\Отборные
условия\Куда\" + m + ".xlsm"

Name OldName As NewName

Next t
book1.Close

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True

End Sub

最佳答案

当您使用字符串时,我会尝试 Dim oldName As String ,然后使用 & 进行连接,而不是 +

您可以使用 CStr(n) 显式转换 n,而不是让它隐式转换。

开头的 ""+ 有何意义?它不会添加任何东西。只需 Cstr(n) & ".xlsm" 就足够了。

n 必须包含完整的文件路径,因为 Name 函数需要位置和文件名。

Name statement:

oldpathname Required. String expression that specifies the existing file name and location — may include directory or folder, and drive.

newpathname Required. String expression that specifies the new file name and location — may include directory or folder, and drive. The file name specified by newpathname can't already exist.

关于vba - 重命名书籍时出现运行时错误 13,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51168002/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com