gpt4 book ai didi

vba - 将一个数组复制到另一个数组

转载 作者:行者123 更新时间:2023-12-04 21:07:58 25 4
gpt4 key购买 nike

我的 Sub 不断在以“<--- HERE”结尾的在线错误。

如果在 Dim 中指定该数组是 Full_Path(2) 我得到 compile error Cannot be assigned to an array .

如果我将数组保留为动态(如下面的示例),我会得到 Run-Time error '13': Type mismatch .

我不明白为什么两者都不起作用?

也可作为输入 Entered_Path = D:\Data\MBS

Sub Set_Folder(Entered_Path As String)
' this function wil point to the folder that you want your data be saved into
Dim Drive As String, Folder As String
Dim Full_Path()

'Assign this to a Public Variable
Path = Entered_Path

Full_Path = Split(Entered_Path, ":", , vbTextCompare) <--- HERE
Drive = Full_Path(0)
Folder = Full_Path(1)

ChDrive Drive
ChDir Folder
End Sub

最佳答案

您可能不需要所有这些变量。

查找 Split()

Sub SetFolder(Entered_Path)
ChDrive Split(Entered_Path, ":")(0)
ChDir Split(Entered_Path, ":")(1)
End Sub

这显然是假设您的路径始终采用以下格式 DRIVE:\FOLDER\SUB

关于vba - 将一个数组复制到另一个数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25405049/

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