EXCEL VBA获取Const文件夹


0

我有一个代码“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

Answers:


3

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

Dim csMyPath As String: csMyPath = vaFiles1
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.