EXCEL VBA 获取源文件夹到 Const

EXCEL VBA 获取源文件夹到 Const

我有一个代码“copyMultFiles”将多个文件中的多个值移动到单个文件我的问题是不能在“Const”中使用参数

错误这一行“ Const csMyPath As String = vaFiles1 ” vaFiles1 是获取源文件夹,我无法在 csMypath 中输入

 'get source folder
    Dim diaFolder As FileDialog
    Dim vaFiles1  As String
    ' Open the file dialog
    Set diaFolder = Application.FileDialog(msoFileDialogFolderPicker)
    diaFolder.AllowMultiSelect = False
    diaFolder.Show

    'MsgBox diaFolder.SelectedItems(1)
    vaFiles1 = diaFolder.SelectedItems(1)

    '    change these to suit requirements
    Const csMyPath As String = vaFiles1
    Const csMyFile As String = "*.xls" 'source search pattern
    Const csSRng As String = "$B$5,$G$36,$I$36,$G$37,$I$37" 'source range
    Const csTRng As String = "$A$1" 'target range

答案1

您不能声明非常量。您正在运行时设置变量,因此您需要将其设为变量。

Dim csMyPath As String: csMyPath = vaFiles1

相关内容