Vba 用自动化替换Application.Getopenfilename

Vba 用自动化替换Application.Getopenfilename,vba,Vba,我想把下面的代码转换成一个用户不需要选择文件的代码 此代码用于从特定文件夹中的所有工作簿中选择特定工作表,例如“C:\Test” 这是合并宏的一部分 sub open_issues_sheet() Dim Files as Variant Files = Application.GetopenFilename("Excel FIles (*xl*),*xl*",Title:="Select Files", Multiselect:=True) For Z = LBound

我想把下面的代码转换成一个用户不需要选择文件的代码

此代码用于从特定文件夹中的所有工作簿中选择特定工作表,例如“C:\Test”

这是合并宏的一部分

sub open_issues_sheet()
Dim Files as Variant 

Files = Application.GetopenFilename("Excel FIles (*xl*),*xl*",Title:="Select Files",         Multiselect:=True)

 For Z = LBound(Files) To UBound(Files)
 tem=Split(Files(Z),"\")
 If(tem(UBound(tem)) <> ThisWorbook.Name) Then 

 Set S= Workbooks.Open(Files(Z))

 S.Sheets("Issues").Select
sub-open\u-issues\u-sheet()
变暗文件作为变量
Files=Application.GetopenFilename(“Excel文件(*xl*),*xl*”,标题:=“选择文件”,多选:=True)
对于Z=LBound(文件)到UBound(文件)
tem=拆分(文件(Z),“\”)
如果(tem(UBound(tem))ThisWorbook.Name)那么
设置S=工作簿。打开(文件(Z))
S.Sheets(“问题”)。选择
'要复制到当前工作表的代码

我试过用这个


但是我在“For Z=LBound”行中遇到了一个“类型不匹配”错误,假设您仍然需要用户选择包含需要合并的文件的文件夹,使用FileDialog(msoFileDialogFolderPicker)是可以接受的解决方案

Dim sFilePath As String

With Application.FileDialog(msoFileDialogFolderPicker)
    .AllowMultiSelect = False
    .Title = "Select folder to consolidate"
    If .Show = -1 Then

        'Get the first file listed in the folder
        sFilePath = Dir(.SelectedItems(1) & "\")

        Do While Not sFilePath Like vbNullString

            'Verify the extension before opening file
            If Mid$(sFilePath, InStrRev(sFilePath, ".")) Like ".xls" Then

                ' Perform task ...

            End If

            'Get next file
            sFilePath = Dir
        Loop
    End If
End With