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

标签 vba excel

我的 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/

相关文章:

mysql - 带有 google 文档的电子邮件

vba - Microsoft Word 中的拼写错误

python - 有没有一种方法可以将 Excel 工作簿合并到 python 中的一个主工作簿中?

excel - 逻辑解析 Excel 中的字符串以修剪附近的重复项

vba - 从电子邮件中提取第 3 行和第 4 行

vba - Excel 中某些子字符串之间的文本格式和颜色

vba - 如何使用 VBA 在 Word 2010 文档中永久存储变量?

Excel VBA 基于 VbMsgBoxResult 重新启动其内部相同的子例程

excel - 以相同缩放打印两种不同纸张尺寸的宏

vba - VB6 检查将被覆盖的文件是否打开